Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2009
    Posts
    17

    Thumbs up Unanswered: Please Help What Similarity of this query...:eek: :eek:

    Hi guys...

    i stuck for the similiarity of this code

    SELECT DATEADD(day, DATEDIFF(day, 0, getdate()-2) /7*7 , 0);

    the problem is if i convert the getdate() function with date value
    the result is error converting int.

    Ex.
    SELECT DATEADD(day, DATEDIFF(day, 0, '01/01/2009' - 2) /7*7 , 0);


    anyone could help me with this situation??

    Regards,
    Thomas Benny

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Code:
    SELECT DATEADD(day, DATEDIFF(day, -2, '01/01/2009') /7*7 , 0);
    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Feb 2009
    Posts
    17

    Thanks for reply Path....thanks and greatfull for your help

    Dear path or other members.

    Actually i need the date of the monday where date i input as parameter

    ex.

    if i used your query pat

    declare @date as datetime;
    set @date = '05/23/2009'

    SELECT DATEADD(day, DATEDIFF(day, -2, @date ) /7*7 , 0)

    the query return wrong result : 25 May 2009

    which is date i want as the result should be :
    18 May 2009 <<-- it's mean the monday date. how's the query should be?,please help me...

  4. #4
    Join Date
    Feb 2009
    Posts
    17

    Thanks Path u r Marvelous

    Code:
    declare @date as datetime;
    set @date = '05/29/2009'
    
    SELECT DATEADD(day, DATEDIFF(day, 0, @date ) /7*7 , 0)
    Case Closed, Viva dbforums.com





    Regards,
    Thomas Benny

Posting Permissions

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