sql - Need to calculate the current date till end year? -


i automating report has 3 dates set parameters, user enters. note our dates in yyyymmdd format.

we want first set current date: totext(currentdate, 'yyyymmdd') till end of year. can hard code 20151231 prefer not to. how script last day of year?

assuming using sql server of recent-ish vintage:

  • current date:
    select today = convert(date, current_timestamp )

  • 1st day of current month:
    select first_of_month = convert(date, dateadd(day, 1-day(current_timestamp) , current_timestamp ) )

  • last day of current month:
    select last_of_month = convert(date, dateadd(day, 1-day(dateadd(month,1,current_timestamp)) , dateadd(month,1,current_timestamp) ) )

  • 1st day of current year:
    select first_of_year = convert(date, dateadd(day, 1-datepart(dayofyear,current_timestamp) , current_timestamp ) ) ,

  • last day of current year:
    select last_of_year = convert(date, dateadd(year,1, dateadd(day, -datepart(dayofyear,current_timestamp) , current_timestamp ) ) )


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -