homepage Welcome to WebmasterWorld Guest from 54.163.72.86
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Performing math with time
Finding out elapsed time between two times
sawatkins




msg:3642474
 2:54 am on May 6, 2008 (gmt 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>

 

kbts




msg:3642514
 4:43 am on May 6, 2008 (gmt 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

sawatkins




msg:3643202
 7:06 pm on May 6, 2008 (gmt 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?

wtkad




msg:3643262
 7:51 pm on May 6, 2008 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved