Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

finding Next Sunday's date for SQL statement

Status
Not open for further replies.

SirLars

Technical User
Oct 24, 2000
47
CA
I am new to php and have come across my first real obstacles...

meaning I need to populate a table with names from ANOTHER table of volunteers.
organized by
volunteer_ID, name, phone_num

I am putting up a schedule online and each field is organized by date, position1, position2, position3 etc

where positions are of type INT (relating to ID of person in volunteer table)

NOW, my problem is how can I make a sql statement that will select ONLY the field co-responding to "the next sunday (or today if it's sunday)"

Ie, (SELECT * FROM volunteers WHERE date_index = next sunday)
 
You havent specified the database and version you are using.
Also what is the type of field 'date_index' ?

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Try

SELECT * FROM volunteers WHERE date_index = DATE_FORMAT(CURDATE(),"%w")

This should work if you are using mysql and date_index is an INTEGER value which is 0 for sunday, 1 for monday and so on...
 
spookie: date_index is mysql field of type DATE

all fields have a "day" value of Sunday... when using the date( "d m y" ,strtotime(date_index)) formula...
all the dates ARE sundays.

I need the webpage to display the UPCOMING sunday's fields

-----

I guess, what I'm asking for is simpler code to find the NEAREST sunday to today's date.

A "clumsy" way would be to

$today=date(w); what day is today?

is $today sunday? (0/zero)
$difference = $today

how far away is sunday?
$dateuwant=date() + $today.

I think?

 
correction

difference = 7-$today;
if it's 7 then you want it to be changed to 0;

because w returns 0 for sunday and 6 for saturday
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top