dates: 12 mos ending with prev mo end.

  • I need to fill 2 parameters with starting and ending dates of a 12 month period that closed the last day of the month preceding the current one. Suggestions? (watch out for Leap Year)

  • Are times a part of the data?  This returns the last possible datetime value on the last day of the previous month:

    select dateadd(day, -1, convert(char(6), CURRENT_TIMESTAMP, 112) + '01 11:59:59.997PM')

    This returns the first datetime value on the first day of the month 12 months before the previous month (try saying that three times fast):

    select DATEADD(m, -12, convert(char(6), CURRENT_TIMESTAMP, 112) + '01')

    So if this is July 15, 2005 (hey, it is!) the first select returns "2005-06-30 23:59:59.997"

    and the second select returns "2004-07-01 00:00:00.000".

    There is no "i" in team, but idiot has two.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply