...

View Full Version : Anyone knows how to query according to the date..



che_anj
08-28-2007, 09:17 AM
Id like to have a query depending on what is the date today. Its like a sort of reminder.

example. I have insert an action "Call Mr. Smith" and the date assigned is 2007-08-29 so by tommorow when i open my list of actions it will appear the the said "Call Mr. Smith" .

my query is

Select * from schedule where enddate<=NOW()

but this query will display all the enddate that less than 2007..

Thanks..

Bahamut
08-28-2007, 09:41 AM
$datenow = date("Y-m-d");
$sql = "SELECT * FROM schedule WHERE enddate = '$datenow'";


or



$sql = "SELECT * FROM schedule WHERE enddate >= '$datenow 00:00' AND enddate <= '$datenow 23:59'";


depends whether field is date or datetime

che_anj
08-28-2007, 10:13 AM
what if i want to display list of actions which less than end date assigned..

heres the scenario..

start dates
2007-08-23 - meeting
2007-08-24 - call smith
2007-08-25- 1st interview
2007-08-26- 2nd inteview

end date
2007-08-25- meeting
2007-08-29- call smith
2007-08-28-1st interview
2007-08-31-2nd interview

the very end date is 2007-08-31, therefore the actions displays are from 2007-08-28 to 2007-08-31, or todays date to very last date..

tnx

Bahamut
08-28-2007, 10:21 AM
$sql = "SELECT * FROM schedule WHERE startdate >= '$datenow' OR enddate >= '$datenow'";

che_anj
08-28-2007, 10:27 AM
Thanks Bahamut.. ;)

Mwnciau
08-28-2007, 02:04 PM
You can use the SQL function CURDATE() instead of using a PHP function:


$sql = "SELECT * FROM schedule WHERE startdate >= CURDATE() OR enddate >= CURDATE();";



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum