Creating and comparing date/time, preferred format?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Creating and comparing date/time, preferred format?

Post by JAB Creations »

In regards to comparing date/time what format is best to use to compare two sets of date/time? I was reading something about Unix formatted time stamps on php.net and then found some reading on the Unix Epoch...I'm not really sure what would be the most proper/long term solution I should use though?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Creating and comparing date/time, preferred format?

Post by requinix »

It's really just personal preference. Dates as numbers (eg, 1258322483) can be compared to other numbers just as easily as dates as strings (eg, "2009-11-15 14:01:23") can be compared to other strings.

However, since the end product is most often a string, numbers are easier to deal with because there's only one conversion. With strings they get converted to numbers and then back to strings: except for MySQL which can reformat a date string in one step... but that means doing the conversion in the SQL. All in all, numbers are easier to deal with in PHP but strings are easier in MySQL.
Post Reply