View Full Version : Compare Mysql current timestamp with todays date

03-05-2008, 11:38 AM
Hi there, I'm looking to compare a timestamp that was automatically created by the mysql database when each record was created with todays date. Firstly i believe i have to get it into the same format tho and was looking for pointers on how to do this.

Currently if i echo the value of the timestamp in one of the database records it reads: 2008-02-15 15:31:14

Been looking around but haven't had much luck on this, so wondering if you guys could help.


03-05-2008, 01:15 PM
Have kinda got it working, although aving problems comparing if the date posted equas todays date.

Here's what i have:

$todays_date = date("d M Y");
$today = strtotime($todays_date);
$date = date("d M Y", strtotime($row["date_posted"]));
if($date == $today){
$dateposted = "Today";

else {
$dateposted = $date;

It is in a while statement that shows a number of records on the page at once, altho i don't think this shud interfere with it as it is in the while statement and shud happen for each record.

Any ideas? Is it not possible to use = when comparing dates?

03-05-2008, 01:24 PM
Sorry, guys never mind about bout this, have seen my error. I didn't need line:

$today = strtotime($todays_date);

Have it working now

03-05-2008, 02:40 PM
If you want to know if a date (in a DATETIME) field in your database is equal to the current date, do it directly in your query. No conversion or slow php code is necessary -

SELECT your_columns FROM your_table WHERE DATE(date_posted) = CURDATE()