Results 1 to 7 of 7

Thread: SQl date calculation

  1. #1
    Join Date
    Oct 2002
    Location
    queens
    Posts
    139

    SQl date calculation

    I need to use the first day of previous month, can anybody help me with that please?

    Thanks in advance!!

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254

  3. #3
    Join Date
    Oct 2002
    Location
    queens
    Posts
    139
    I can't use the function, I need it as aquery.

    I have the last day of last month:

    select dateadd(ms,-3,DATEADD(mm, DATEDIFF(mm,0,getdate() ), 0))

    can't figure out how to get the first day of last month....

  4. #4
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    select convert(datetime,left(Convert(varchar(8),dateadd(M ,-1,getdate()),112),6)+'01',112)

  5. #5
    Join Date
    Dec 2004
    Posts
    502
    Another way:

    SELECT DATEADD(m, DATEDIFF(m, 0, getdate()) -1, 0)

  6. #6
    Join Date
    Dec 2004
    Posts
    502
    You can also do this to get the last date of last month:

    SELECT DATEADD(m, DATEDIFF(m, 30, getdate()) -1, 30)

  7. #7
    Join Date
    Oct 2002
    Location
    queens
    Posts
    139
    Thank you, that worked.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •