dumbnoob Posted January 25, 2010 Share Posted January 25, 2010 A quick summary. I use JS to pull a time and date off of a page on an external site, and dump it into a mysql database using PHP. The date is in the format DD/MM/YYYY with the '/'s as it's dividers, and the time HH:MM:SS Now, I need to be able to use the dates and times pulled from the database, to compare against another date and time set, pulled from the same page at a different time. At present, what I have, is a javascript alert, that outputs something like... ---------------------------------------------------------------------------------------------- Your EVENT {17605244} Occurred sometime between EVENT ID:17603454 - Occured at - 20:25:49 23/01/2010 EVENT ID:17608883 - Occured at - 0:08:55 24/01/2010 ---------------------------------------------------------------------------------------------- I need to be able to add a line to that, that uses yet another time date (Present time date from another server (I already am able to get that)) to give an output of something like... ---------------------------------------------------------------------------------------------- Your EVENT {17605244} Occurred sometime between EVENT ID:17603454 - Occured at - 20:25:49 23/01/2010 Approximately 32 Hours and 58 Minutes ago EVENT ID:17608883 - Occured at - 0:08:55 24/01/2010 Approximately 27 Hours and 43 Minutes ago ---------------------------------------------------------------------------------------------- How would I go about using the values I have, to assign the values I need. It's occurred to me that I maybe able to do it with unix timestamps, as I am tracking them also, though I would prefer to do it using the date and time variables I pull from the other server. Link to comment https://forums.phpfreaks.com/topic/189710-php-need-to-convert-time-and-date-to-total-hours-and-minutes-difference/ Share on other sites More sharing options...
manwhoeatsrats Posted January 25, 2010 Share Posted January 25, 2010 Convert both times to a unix time stamp. A unix time stamp is how many seconds have passed since 00:00:00 UTC on 1 January 1970. then you can easily do a math problem of Time1 - time 2. after you have done this convert it back to a readable format. Link to comment https://forums.phpfreaks.com/topic/189710-php-need-to-convert-time-and-date-to-total-hours-and-minutes-difference/#findComment-1001197 Share on other sites More sharing options...
dumbnoob Posted January 25, 2010 Author Share Posted January 25, 2010 Yeah, that part is easy enough, but I need to output only Hours and Minutes difference, as apposed to date and time. Link to comment https://forums.phpfreaks.com/topic/189710-php-need-to-convert-time-and-date-to-total-hours-and-minutes-difference/#findComment-1001201 Share on other sites More sharing options...
manwhoeatsrats Posted January 25, 2010 Share Posted January 25, 2010 <?php //lets call the difference between the two unix time stamps $time_between for this example. //There are 60 seconds in every minute. //and 60 minutes in every hour. $total_minutes = $time_between / '60'; $hours = $total_minutes / '60'; $minutes = $hours % '60'; // % is the modulus function to get the remainder of minutes echo $hours . " " . $minutes; ?> I hope this helps Link to comment https://forums.phpfreaks.com/topic/189710-php-need-to-convert-time-and-date-to-total-hours-and-minutes-difference/#findComment-1001203 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.