Tags: case, database, date, datediff, datetime, greetings, input, microsoft, mysql, oracle, server, sql, sqlthanks

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

On Database » Microsoft SQL Server

1,755 words with 5 Comments; publish: Tue, 04 Dec 2007 22:02:00 GMT; (25062.50, « »)

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!

All Comments

Leave a comment...

  • 5 Comments
    • Its odd how different people have similar question on this forum at the same time...

      declare .sqlserver.todaysummary.com.datevalue datetime

      set .sqlserver.todaysummary.com.datevalue = '11/12/2003'

      select dateadd(d, datepart(dw, .sqlserver.todaysummary.com.datevalue)-1, .sqlserver.todaysummary.com.datevalue)

      blindman

      #1; Tue, 11 Dec 2007 16:14:00 GMT
    • === Original Words ===

      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?

      #2; Tue, 11 Dec 2007 16:15:00 GMT
    • === Original Words ===

      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]

      #3; Tue, 11 Dec 2007 16:17:00 GMT
    • [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.

      #4; Tue, 11 Dec 2007 16:17:00 GMT
    • 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

      #5; Tue, 11 Dec 2007 16:19:00 GMT