Date additions (T-SQL)

Adding number of x to a date,
where x can be: year=yy, month=m, dayofyear=y, day=d, week=wk, hour=hh, minute=mi, second=ss.

For example adding 260 days to New Year’s day 2011:

print dateadd(d, 260, ‘2011-01-01’)

This should return Sep 18 2011

Advertisements

Calculate days since begninning of the Year (T-SQL)

Calculate days since begninning of the Year:
print datediff(d, ‘2011-01-01’, getdate())

Or get the difference between any two dates; format is datediff(d, ealier date, later date)
print datediff(d, ‘1969-07-20’, ‘2011-09-19’)