简体   繁体   中英

how to display all the possible data greater than the current date

$Date = date("m/d/Y");
$result = mysql_query("SELECT * FROM service WHERE SType = 'Retreat' and Start_date > '$Date' ");

Start_date format is m/d/y also.

whats wrong with my code? all i want to do is to display all the possible data greater than the current date. but it always show all the data from the database.

Use date("Ymd") rather than date("m/d/Y").

Have you looked at this: http://www.bigroom.co.uk/blog/dates-in-php-and-mysql ?

The article suggests you consider doing something like

$result = mysql_query(
    "SELECT * FROM service WHERE SType = 'Retreat' and Start_date > FROM_UNIXTIME($Date)"
);

It's best if you use the YYYY-MM-DD format for dates in MySQL.

It depends on how you store your date. If its stored as a unixtime, then you simply do an equal or greater check and you are on your way.

PHP has some great functions to turn date into unixtime. Like strtotime

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM