Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Performing math with time

Finding out elapsed time between two times



2:54 am on May 6, 2008 (gmt 0)

5+ Year Member

I have to apply some math to time. Here's the deal.

Shifts have a starting time ($timestart) and an end time ($timeend), which are stored in the database as DATETIME.

I need to find out how much time has passed between $timestart and $timeend. It seems like a pretty straightforward thing to do, but I can't seem to Google out an answer.

Can I get a bit of help?




4:43 am on May 6, 2008 (gmt 0)

5+ Year Member

Hi sawatkins,

Searching 'mysql datetime functions' in Google, the first link returns you some relevant results. I believe DATE_SUB() or DATEDIFF() are what you're looking for.

Hope this helps,


7:06 pm on May 6, 2008 (gmt 0)

5+ Year Member

Cool, I'm checking it out right now.

I think, though, that I'm going to need them done in PHP. Does anyone know how?


7:51 pm on May 6, 2008 (gmt 0)

5+ Year Member

The easiest way for me is to convert them to times (strtotime) and subtract the two. Then you have the number of seconds between them, which you can use any way you like.

Featured Threads

Hot Threads This Week

Hot Threads This Month