Welcome to WebmasterWorld Guest from 54.196.153.46

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)

New User

5+ Year Member

joined:Mar 30, 2007
posts:33
votes: 0


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?

Thanks!

</g>

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

New User

5+ Year Member

joined:May 6, 2008
posts:18
votes: 0


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,
kbts

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

New User

5+ Year Member

joined:Mar 30, 2007
posts:33
votes: 0


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)

Junior Member

10+ Year Member

joined:May 17, 2006
posts:48
votes: 0


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.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members