Why not get MySQL to compare your date with today?

e.g.

select if(Booking_Date = curdate(),'booked','free') as Todays_Status ...

$Todays_Status = mysql_result($result,$i, Todays_Status);

echo "you are $Todays_Status today";

I find it is much, much safer to only use the database for finding out the date/time. Why?

My applications typically run where the database and the web-server are on different machines and where there often multiple machines running the web-servers. That means different clocks.

This can cause some really horrid bugs to start appearing e.g. records you just inserted "today" appearing on the next select as yesterday's or tomorrow's, records appearing to be inserted out of order, etc. etc. What makes them so nasty is that you may notice until the data is completely screwed up.

You won't get these problems as long as you only ever use the database server to supply the date/time. You will always get consistent results even if they are consistently a few seconds fast or slow. Records will always appear to have been inserted in the expected order, a row with "today"'s date will show up on every query for today etc. You have to be careful as and when the time is changed on the database server, (which is why they so often do have the wrong time!).

To pick up today from the database server, remember you don't have to have any tables in your query e.g. your query can be as simple (and fast) as :-

select curdate() as today;


Regards,


George

Shaun wrote:
Hi,

I have a date stored in a table in my MySQL Database using a DATE type for
the column.

How can i compare the date in the table to today

e.g.

$today = mysql_result($result, $i, Booking_Date);

if($today = *HELP*){
    echo "you are booked today";
}else{
    echo "you are free today";
}

thanks for your help




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to