Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2004
    Posts
    162

    Unanswered: date time -one week

    Hi

    I need help with a query that returns todays date -one week
    Ex: the 1 december it should return "24" for 24 november.

    this one below works only from the 7th every month else it give me a negative number

    SELECT RIGHT ('0' + CAST(DAY(GETDATE()) - 7 AS varchar); 2)


    Thx in advance


    //Mr

  2. #2
    Join Date
    Jun 2003
    Posts
    269

    Thumbs up

    Code:
    select right('0'+cast(day(getdate()-7)as varchar),2)
    I love cursor,though I never use it.Cos' I dont want to misuse it.
    ----------------------------------------------

    ----cheers
    ----http://mallier.blogspot.com

  3. #3
    Join Date
    Mar 2004
    Posts
    162
    hehe that was an awkward experience thx alot for your help

  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    This formula is more direct and probably more efficient than the method you are using:
    select datepart(day, dateadd(day, -7, getdate()))
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  5. #5
    Join Date
    Jun 2003
    Posts
    269

    Talking

    You can touch your nose with your hand directly or you can touch back through your head.Which one you prefer?
    I love cursor,though I never use it.Cos' I dont want to misuse it.
    ----------------------------------------------

    ----cheers
    ----http://mallier.blogspot.com

Posting Permissions

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