Results 1 to 12 of 12
  1. #1
    Join Date
    Nov 2003
    Posts
    3

    Unanswered: Get Last day of week (Saturday) from any date?

    Greetings,

    Any tips on using datediff to get last day of week( in this case saturday) from a datetime input in SQL?

    Thanks for any help!

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Its odd how different people have similar question on this forum at the same time...


    declare @datevalue datetime
    set @datevalue = '11/12/2003'
    select dateadd(d, datepart(dw, @datevalue)-1, @datevalue)

    blindman

  3. #3
    Join Date
    Aug 2003
    Location
    Stockholm, Sweden
    Posts
    4

    Re: Get Last day of week (Saturday) from any date?

    Originally posted by jackogreen
    Greetings,

    Any tips on using datediff to get last day of week( in this case saturday) from a datetime input in SQL?

    Thanks for any help!
    Are you depending on using datediff? And is date of last weekday you want?

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Originally posted by blindman
    Its odd how different people have similar question on this forum at the same time...

    blindman
    [blinders on]
    Shound I read through other threads or do a search?
    [/blinders on]
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  5. #5
    Join Date
    Oct 2003
    Posts
    706

    Re: Get Last day of week (Saturday) from any date?

    [i]
    Any tips on using datediff to get last day of week( in this case saturday) from a datetime input in SQL?
    In any language, the solution to this problem is to determine the day-of-the-week of the date entered, then calculate the number of days (0-6) to the following Saturday, then add that number of days to the date entered. Q.E.D.
    ChimneySweep(R): fast, automatic
    table repair at a click of the
    mouse! http://www.sundialservices.com

  6. #6
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    No need to search Brett! This gentleman was looking for the first day of the week:
    http://www.dbforums.com/t970121.html

    We also had a slew of people asking about elimination of duplicates recently.

    "In any language, the solution to this problem is to determine the day-of-the-week of the date entered, then calculate the number of days (0-6) to the following Saturday, then add that number of days to the date entered. Q.E.D."? Been there, done that.

    blindman

  7. #7
    Join Date
    Oct 2011
    Posts
    1

    Thumbs up Calculating day of week in SQL server

    To get a deterministic value for the day of week for a given date you could use a combination of datepart and @@firstday. Otherwise your dependent on the settings on the server.

    Check out the following site for a solution:
    MS SQL: Day of Week | LazerWire.com

    The day of week will then be in the range 0 to 6, where 0 is Sunday, 1 is monday, etc

  8. #8
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    gee, what a helpful reply... not

    i do hope that the original poster hasn't been stuck for these last eight years waiting for a solution
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  9. #9
    Join Date
    Sep 2001
    Location
    Chicago, Illinois, USA
    Posts
    601
    Can the operators of this board add some code to prevent users from replying to threads that have not been responded-to in the past month?

    If a post lies dormant for more than a month, and the original poster wants to continue the thread, he/she can reference the previous thread in a new thread.
    Ken

    Maverick Software Design

    (847) 864-3600 x2

  10. #10
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,420
    Provided Answers: 7
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

  11. #11
    Join Date
    Sep 2011
    Posts
    75

  12. #12
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Quote Originally Posted by PracticalProgram View Post
    Can the operators of this board add some code to prevent users from replying to threads that have not been responded-to in the past month?

    If a post lies dormant for more than a month, and the original poster wants to continue the thread, he/she can reference the previous thread in a new thread.
    Occasionally people come up with useful addendums to old issues, so unless the posters are sig-spamming we generally let them be.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.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
  •