|
||||
|
« Setting the "no_adsense_for_me" cookie | Submit your web site to GIDNetwork » |
Get the date / time difference with PHP
by: admin - May 31, 2005
It seems like a really popular question, I was so sure there would already be something ready-made out there. Searching the WWW with my favourite search engine, I was a bit surprised that it was clearly not the case -- okay, there were some example codes that do calculate the difference in time values, but they were not quite what I was hoping to find. Before I paste my custom PHP function to calculate time differences, I need to explain that I have no use for this function myself. A disclaimer like that usually means I am writing it, testing it for a while and then I am done with it. In case you find a bug, I will appreciate it if you let me know, either via the comment link at the bottom of this page or by sending me an email. Overview: get_time_difference()array get_time_difference( string start, string end ) The function expects to be given 2 strings representing the start and end values of a time or date. These strings will be converted to Unix timestamps before the function works with them. Unix timestamp is the number of seconds since January 1, 1970 00:00:00 GMT. The function returns an array that can be described like this: Generic Code Example: $diff['days'] = int $diff['hours'] = int $diff['minutes'] = int $diff['seconds'] = int or returns false on errors. The custom PHP function: get_time_differencePHP Code Example:
Example PHP script using "get_time_difference"Using justinhn's example, here is how you could use this function to get the time difference. PHP Code Example:
The example code will result in this being output: Generic Code Example: Hours: 01:30
|
GIDNetwork Sites
Archives
Recent GIDBlog Posts
Recent GIDForums Posts
Contact Us
|
« Setting the "no_adsense_for_me" cookie | Submit your web site to GIDNetwork » |