First and Last day of the current year expression

  • HI, does any one know how to get the last date of the current year and the first date of the current year - needto use as defaults in a parameter

  • In T-SQL, this will work:

    select [StartOfYear] = DATEADD (year, datediff(year, 0, getdate()), 0),

    [EndOfYear] = dateadd(day, -1, DATEADD(year, datediff(year, 0, getdate()+1), 0))

    Reporting Services is very similar, but I won't have access to it to play around and try it out until tonight.

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • Try this:

    =CDate("1/1/" & Str(Year(Today())))

    or

    =CDate("1/1/" & Str(Year(Now())))

    For the last day just replace the beginning

    =CDate("12/31/" & Str(Year(Today())))

  • WayneS (8/27/2010)


    In T-SQL, this will work:

    select [StartOfYear] = DATEADD (year, datediff(year, 0, getdate()), 0),

    [EndOfYear] = dateadd(day, -1, DATEADD(year, datediff(year, 0, getdate()+1), 0))

    Reporting Services is very similar, but I won't have access to it to play around and try it out until tonight.

    For end of year: DATEADD(year, DATEDIFF(year, -1, getdate()) + 1, -1)

    Jeffrey Williams
    Problems are opportunities brilliantly disguised as insurmountable obstacles.

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Thanks all perfect

Viewing 5 posts - 1 through 4 (of 4 total)

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