get the Next Sunday
My table is structured as follows.
SundayDate - Date
Helper1 - VarChar(25)
Helper2 - VarChar(25)
Helper3 - VarChar(25)
Helper4 - VarChar(25)
Helper5 - VarChar(25)
Helper6 - VarChar(25)
I want to display the names of all the helpers that are that are associated with the next Sunday to come.
For example, say I have 2 rows in my table:
2008/01/13 John James Henry Albert Peter George
2008/01/20 Ruth David Philip Simon Mikey Daniel
Today is 2008/01/10, so I want to select John, James, Henry, Albert, Peter and George as the next Sunday after the today is 2008/01/13.
I realise I need to get the date of the next Sunday (str_NextSundayDate). Once I have this date then I do something like :
"SELECT * FROM table WHERE SundayDate = str_NextSundayDate"
The bit I'm not sure of is how to work out what date the next Sunday will be.
Can anyone advise?
I have done something similar to find the next saturday, feel free to amend as needed
$datecalc = strtotime(“Saturday”);
$datesearch = date(“Y,m,d”,$datecalc);
$conn = @mysql_connect(“localhost”,”********”,”********”);
Squery = “SELECT * FROM table WHERE date = $searchdate”;
You can get next Sunday in this one-liner, if you like:
$str_NextSundayDate = date('Y-m-d', strtotime('next Sunday'));
"SELECT * FROM table WHERE SundayDate = '$str_NextSundayDate'"
I had the same problem as you
Originally Posted by john noble
If you need a solution, try this
Hope this helps
For computing the coming Sunday
Just test the following Block - You will get the next sunday
DECLARE @TEST_DATE DATETIME
SET @TEST_DATE = '12/27/2010' --GETDATE()
select @TEST_DATE as TODAY,
datepart (dw, @TEST_DATE) as dayOfTheWeek,
datename (dw, @TEST_DATE) as NameOfDay,
DATEADD(DAY, (8-datepart (dw, @TEST_DATE)), @TEST_DATE) NEXT_SUNDAY
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)