DATEDIFF two dates 1 year apart

For a friend who needed to know how to check if two dates in Sybase ASE 12 are a year apart. A JavaScript Solution Add moment.js lib // TODO: Validate if date diff is no more than 1 year var startSepDt = moment($(‘#startDateSep’).val()); var endSepDt = moment($(‘#sendDateSep’).val()); var dateDiff = endSepDt.diff(startSepDt, ‘year’); if (dateDiff > 1)  {        showInValidSeasrchWarning(‘The date range cannot exceed a year.’);        return false; }   A SQL Solution — DATEDIFF two dates 1 year apart DECLARE @year1 datetime, @year2 datetime SET @year1 = […]

Dynamic Search Conditions in T‑SQL

I hate dynamic querys as they are not optimized and a query plan cannot be cached…. Example: Sql = some dyanamic sql string built via if logic… Exec(sql) – will not cache an query execution plan. In MS Sql   sp_executesql caches query plans – very cool… Really though, try to avoid them if possible….   […]