Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Iban Dominguez
17,973 PointsPHP MYSQL COMPARE DATETIME VALUES
Hi there!
I am building a php mysql calendar web app where events get assigned to different users.
I often have to compare dates from mysql to not duplicate the same users on another event at the same time.
At the moment I am storing the values in MYSQL as datetime and creating a date '2014-04-12' string to compare within the php script.
I've seen some apps that compare dates as whole number for example: 46847684687 > 657687
Any advice of best format to compare datetimes?
thanks beforehand! cheers!
2 Answers

Travis Neiderhiser
1,027 PointsI personally convert the record to an int then use the date method in PHP.
$datetime = strtotime($mysqlDate);
$recordDate = date("y-m-d", $datetime);
if($recordDate == '2014-04-12') {
}
Sounds like that is what you are doing?

Iban Dominguez
17,973 PointsHi Travis,
kind of what I am doing! if it works for you I guess it will work for me too!
cheers!