0

Is this possible, and if so, how do I get this working?

If datetime from table is greater than another datetime from table, then run query.


so pretend its:

$date1 = $row["date1"]; (june 19th) (i have a query on the page were it updates the day everytime you visit, NOW())

$date2 = $row["date2"]; (june 20th)


if ($date1 > $date 2) {
RUN QUERY; }


But that above statement isn't working.


if anyone could help, thanks.

3
Contributors
4
Replies
7
Views
7 Years
Discussion Span
Last Post by Zagga
0

Hi griffith,

You are trying to do a numerical comparison of strings that contain words. Try storing the date in the database in a date format (YYYYMMDD) so June 19th 2010 will be 20100619. Your comparisons should work then.

Hope this helps.
Zagga

Edited by Zagga: n/a

0

In the MySQL table, how do you make it YYYYMMDD?

Field
Type <<< I don't see date format YYYYMMDD in the type drop down menu
Length/Values
Default
Collation

etc

0

type = "date".

:)

This will store the date as YYYY-MM-DD.
You can then strip out the "-" seperators and compare the dates

$date1 = str_replace("-", "", $date1);
$date2 = str_replace("-", "", $date2);
If($date1 > $date2){
   run your query here;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.