Jump to content

Difference in two time/dates


tmcdonnell

Recommended Posts

I assume you insert the date in the database in normal format (e.g m/d/y or y-m-d etc), because if you insert as timestamp, then a simple subtraction would work.

 

if you want to get exact difference in seconds, you should go for

$sec_diff=strtotime($date1)-strtotime($date2);

 

then of course you could convert this seconds to months/days/hours etc.

Depends on the approach and what you're comparing. That being said, if it is a small to medium sized database, I will use both. One field/column for a timestamp and a second field with the date (Format - 2008-1-31). The timestamp will give me the hour of the day and an exact time, if I ever need it...and I won't ever have to question how to compare dates. I can also query using the "Date" formatted column. Makes life easy.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.