In the database column called date (tyupe int(11)) I have stored the date as integer. Then, I have variables $day, $month, $year and I would need to get all rows for the respective day (which represent variables $day, $month, $year).
How to do that?
I’ve tried this way:
mysql_query("SELECT id FROM persons WHERE DATE_FORMAT( `date` , '%Y-%m-%d' ) =
'".date("$year-$month-$day")."'")
But this unfortunately doesn’t works me… Could anyone give me a tip, please, how to solve this problem?
Thanks
You’ll want to avoid having to wrap your date column in a function in order to still be able to utilize indexes.
This is the most efficient method for your scenario, provided you have an index set up on the
datecolumn:It would be an even better idea to actually store the
datecolumn as an actualDATEtype. That way, you can make all sorts of compelling date comparisons and calculations that you otherwise couldn’t with a simple integer-based unix timestamp.