Forum Moderators: coopster
I am trying to query my database and echo results where the date of the entry is equal to or greater than today. Currently, it kinda works, but it echoes everything. Below is my MySQL query which is in my code:
$today = date("j, n, Y");
$sqlquery = "SELECT timestamp, diwtitle, id from diw_alpha WHERE timestamp >= '$today'";
The variable 'timestamp' is a timestamp column in my table in the format:
date("Y-m-d h:i:s")
So.. I am not sure if my query echoes everything because there is a difference in date syntax ("j, n, Y") vs. ("Y-m-d h:i:s") or if there is a correct way to do the query.. Does anyone have an idea what I am not doing right?
Thanks! :)
As for no items returned, try the query in the mysql shell or through phpMyAdmin and see if it returns any results. It could tell you if there is a problem with the query.
If all else fails, change the timestamp format to datetime. This is MySQL's default date format and is easier all around to use.
SELECT timestamp, diwtitle, id from diw_alpha WHERE timestamp >= CURDATE()
or
SELECT timestamp, diwtitle, id from diw_alpha WHERE timestamp >= NOW()
I get zero results in phpmyadmin, but when I type
SELECT timestamp, diwtitle, id from diw_alpha
I get plenty. I am not sure what I am doing wrong, as I haven't used the datetime() function before.. But I am reading about it now! If you see something glaring, or have another clue, please let me know :)
Thank you!
You can play around with this some at the MYSQL prompt to get a better idea of waht happens.
Example:
mysql> SELECT NOW()-0, NOW()-1;
+----------------+----------------+
¦ NOW()-0 ¦ NOW()-1 ¦
+----------------+----------------+
¦ 20050412173727 ¦ 20050412173726 ¦
+----------------+----------------+
1 row in set (0.00 sec)