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
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Getting StartDate and EndDate using SQL query

Getting StartDate and EndDate using SQL query

Scheduled Pinned Locked Moved Database
databasesql-serversysadminhelptutorial
3 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.
  • M Offline
    M Offline
    meeram395
    wrote on last edited by
    #1

    Hi, I have a requirement to select the starting date and ending date of a month if I give a particular date as a parameter. HOw to do that? For eg> If I give the select statement as below: select startdate, enddate from where particulardate = '17/03/2008'. If I execute this query, I should get the start date as '01/03/2008' and end date as '31/03/2008' HOw to achieve this in SQL Server? Pls help Regards meeram.

    Meeram395

    K 1 Reply Last reply
    0
    • M meeram395

      Hi, I have a requirement to select the starting date and ending date of a month if I give a particular date as a parameter. HOw to do that? For eg> If I give the select statement as below: select startdate, enddate from where particulardate = '17/03/2008'. If I execute this query, I should get the start date as '01/03/2008' and end date as '31/03/2008' HOw to achieve this in SQL Server? Pls help Regards meeram.

      Meeram395

      K Offline
      K Offline
      Krish KP
      wrote on last edited by
      #2

      Getting End Date 1. Add 1month to the given date taking 1st day and year of given date 2. which returns 1st of next month from given date 3. subtract 1day which returns last day of given month DECLARE @GivenDate AS DateTime SET @GivenDate = GetDate() SELECT DateAdd(DD, -1, DateAdd(MM, 1, Cast(Month(@GivenDate) AS VarChar(2)) + '/01/' + Cast(Year(@GivenDate) AS VarChar(4)))) Getting Start date similar to the end date take day as 1 with month & year from given date

      Regards KP

      M 1 Reply Last reply
      0
      • K Krish KP

        Getting End Date 1. Add 1month to the given date taking 1st day and year of given date 2. which returns 1st of next month from given date 3. subtract 1day which returns last day of given month DECLARE @GivenDate AS DateTime SET @GivenDate = GetDate() SELECT DateAdd(DD, -1, DateAdd(MM, 1, Cast(Month(@GivenDate) AS VarChar(2)) + '/01/' + Cast(Year(@GivenDate) AS VarChar(4)))) Getting Start date similar to the end date take day as 1 with month & year from given date

        Regards KP

        M Offline
        M Offline
        meeram395
        wrote on last edited by
        #3

        Thank you very much

        Meeram395

        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