lenerd3000 Posted May 7, 2008 Share Posted May 7, 2008 just a simple question. how can i know the hour difference of yesterday and today.. like: 2008-05-06 13:00:00 - 2008-05-06 12:00:00 = 1 hour Quote Link to comment https://forums.phpfreaks.com/topic/104593-getting-date-and-time-difference/ Share on other sites More sharing options...
Barand Posted May 7, 2008 Share Posted May 7, 2008 Convert them to unix times with strtotime() Subtract, giving difference in seconds. Divide difference by 3600. Quote Link to comment https://forums.phpfreaks.com/topic/104593-getting-date-and-time-difference/#findComment-535361 Share on other sites More sharing options...
blackcell Posted May 7, 2008 Share Posted May 7, 2008 Sorry that didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/104593-getting-date-and-time-difference/#findComment-535383 Share on other sites More sharing options...
revraz Posted May 7, 2008 Share Posted May 7, 2008 And without you showing the code, we can't say where your error is. Sorry that didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/104593-getting-date-and-time-difference/#findComment-535397 Share on other sites More sharing options...
947740 Posted May 7, 2008 Share Posted May 7, 2008 <?php $firsttime = strtotime(2008-05-06 12:00:00 ); # The first time $secondtime = strtotime(2008-05-06 13:00:00); # The last time $difference = $secondtime - $firsttime; $difference = $difference / 3400; ?> Quote Link to comment https://forums.phpfreaks.com/topic/104593-getting-date-and-time-difference/#findComment-535403 Share on other sites More sharing options...
Barand Posted May 7, 2008 Share Posted May 7, 2008 date strings need quotes $firsttime = strtotime('2008-05-06 12:00:00' ); and there's a typo with the 3600 Quote Link to comment https://forums.phpfreaks.com/topic/104593-getting-date-and-time-difference/#findComment-535405 Share on other sites More sharing options...
947740 Posted May 7, 2008 Share Posted May 7, 2008 Of course, I try to help and I look like an idiot. Quote Link to comment https://forums.phpfreaks.com/topic/104593-getting-date-and-time-difference/#findComment-535406 Share on other sites More sharing options...
lenerd3000 Posted May 7, 2008 Author Share Posted May 7, 2008 thanks to all ill try that... and how can i turn it back to time? the strtotime? Quote Link to comment https://forums.phpfreaks.com/topic/104593-getting-date-and-time-difference/#findComment-535407 Share on other sites More sharing options...
947740 Posted May 7, 2008 Share Posted May 7, 2008 You would not be able to change that back to a time. Quote Link to comment https://forums.phpfreaks.com/topic/104593-getting-date-and-time-difference/#findComment-535409 Share on other sites More sharing options...
wildteen88 Posted May 7, 2008 Share Posted May 7, 2008 You would not be able to change that back to a time. Yes you can. Use the date function $unixtime = strtotime('+5 days'); // get the unix timestamp 5 days from now // make time human readable echo date('d-m-Y', $unixtime); Quote Link to comment https://forums.phpfreaks.com/topic/104593-getting-date-and-time-difference/#findComment-535524 Share on other sites More sharing options...
lenerd3000 Posted May 8, 2008 Author Share Posted May 8, 2008 oh great... thank you again. that will solve my problem Quote Link to comment https://forums.phpfreaks.com/topic/104593-getting-date-and-time-difference/#findComment-535769 Share on other sites More sharing options...
947740 Posted May 8, 2008 Share Posted May 8, 2008 In this case, the time would be one hour. You can not change one hour to a time. Quote Link to comment https://forums.phpfreaks.com/topic/104593-getting-date-and-time-difference/#findComment-535885 Share on other sites More sharing options...
lenerd3000 Posted May 8, 2008 Author Share Posted May 8, 2008 I only need the interval of the two expressions. I am making our timeclock for our employee time record. any suggestion/idea/scripts for this project? Quote Link to comment https://forums.phpfreaks.com/topic/104593-getting-date-and-time-difference/#findComment-535908 Share on other sites More sharing options...
947740 Posted May 8, 2008 Share Posted May 8, 2008 So...you want a script that keeps track of how many hours they work each week? (Or something like that?) Quote Link to comment https://forums.phpfreaks.com/topic/104593-getting-date-and-time-difference/#findComment-535910 Share on other sites More sharing options...
robos99 Posted May 8, 2008 Share Posted May 8, 2008 If this is a timeclock, you'll need to consider just how the hour is broken up. Most companies pay you in 15 minute increments, and they have rules set to determine at what point the current 15 minute block will rollover to the next one. As in, punch in at 3:47 it rounds you to 3:45, but punch in at 3:55 and it rounds you up to 4. Unless of course you want to pay them for exactly the amount of time worked and not round in 15 minute blocks. Quote Link to comment https://forums.phpfreaks.com/topic/104593-getting-date-and-time-difference/#findComment-536056 Share on other sites More sharing options...
blackcell Posted May 8, 2008 Share Posted May 8, 2008 That's just short of robbing somebody. No I take it back that's worst. Quote Link to comment https://forums.phpfreaks.com/topic/104593-getting-date-and-time-difference/#findComment-536125 Share on other sites More sharing options...
lenerd3000 Posted May 8, 2008 Author Share Posted May 8, 2008 rounding up is really my problem. since there is no fixed time for some of the employees. i decided to make a schedule of work as my reference and will be encoded in the database but since they can assign another employee to any time, any day, that will be useless. i work in a call center so there are agents who will be rescheduled on night at this time or day at that time. if i make it to 9 working hours, some can extend to 15hours or how about it is overtime. Quote Link to comment https://forums.phpfreaks.com/topic/104593-getting-date-and-time-difference/#findComment-536132 Share on other sites More sharing options...
robos99 Posted May 8, 2008 Share Posted May 8, 2008 That's just short of robbing somebody. No I take it back that's worst. It may not be the most liked practice, but it's fairly typical from what I've seen. Personally I'm not going to make a big deal out of being "robbed" of a few minutes. I just learn the pattern of the time clock and take advantage of it, haha. Quote Link to comment https://forums.phpfreaks.com/topic/104593-getting-date-and-time-difference/#findComment-536212 Share on other sites More sharing options...
blackcell Posted May 14, 2008 Share Posted May 14, 2008 Whatever Quote Link to comment https://forums.phpfreaks.com/topic/104593-getting-date-and-time-difference/#findComment-540907 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.