PHP MYSQL Question on comparing dates in a Query
I开发者_运维知识库 am trying to construct a mysql query string to pull out certain records but only if the date in the database is greater than the current date.
So I have this so far and I am not sure if this is a legal syntax...
date_default_timezone_set('America/Los_Angeles');
$current_date = date("Y-m-d");
$sql = "SELECT * FROM `coupons` WHERE status = 1 AND end_date > '$current_date'";
Thanks for your help.
It's legal syntax. You can use one.
I use CURRENT_TIMESTAMP
in general, i.e.:
SELECT * FROM `coupons` WHERE status = 1 AND end_date > CURRENT_TIMESTAMP
Do you have a need to compare to the LA timezone? CURRENT_TIMESTAMP
will use the local MySQL server time (but that should technically be what the date values are stored as, as well).
精彩评论