Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Problem related to getting date

Problem related to getting date

Scheduled Pinned Locked Moved Database
helpdatabasesql-serversysadmin
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    biswa47
    wrote on last edited by
    #1

    Hi friends I want to select two date from sys. 1st date is 1-April-2007 where Day 1st= is fixed Month April is also fixed But Year 2007 is the current year-1 and the 2nd date is 31-Dec-2007 where day 31st/30th/28th/29th is the last day of the previous month.means current month -1 and Year 2007=Current year-1 for the month of January and for the other months its fixed that is 2008 menas the current year. well i am using SQL SERVER 2005.pLZ help me out.

    A 1 Reply Last reply
    0
    • B biswa47

      Hi friends I want to select two date from sys. 1st date is 1-April-2007 where Day 1st= is fixed Month April is also fixed But Year 2007 is the current year-1 and the 2nd date is 31-Dec-2007 where day 31st/30th/28th/29th is the last day of the previous month.means current month -1 and Year 2007=Current year-1 for the month of January and for the other months its fixed that is 2008 menas the current year. well i am using SQL SERVER 2005.pLZ help me out.

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      I think this will do it - it looks a bit horrendous and I'm sure there must be an easier way :sigh: declare @start datetime, @end datetime, @month varchar(10) set @month = 'feb' select @start = convert(datetime, '01-Apr-' + convert(varchar,datepart(year,dateadd(year,-1,getdate())))) select @start select @end = convert(datetime,dateadd(day,-1,dateadd(year,1,convert(datetime, '01-' + @month + convert(varchar,datepart(year,dateadd(year,-1,getdate()))))))) select @end

      Bob Ashfield Consultants Ltd

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups