note 52684 modified in function.strtotime by colder
| From: | colder@php.net | Date: | Mon, 26 Jan 2009 18:18:22 +0000 |
| Subject: | note 52684 modified in function.strtotime by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-149794@lists.php.net to get a copy of this message | ||
Here's a quick one-line function you can use to get the time difference for relative times. But
default, if you put in a relative time (like "1 minute"), you get that relative to the
current time. Using this function will give you just the time difference in seconds:
<?php function relative_time( $input ) { return strtotime($input) - time(); } ?>
For example "1 minute" will return 60, while "30 seconds ago" will return -30
Valid relative time formats can be found at http://www.gnu.org/software/tar/manual/html_chapter/Date-input-formats.html#SEC114
--was--
Here's a quick one-line function you can use to get the time difference for relative times. But
default, if you put in a relative time (like "1 minute"), you get that relative to the
current time. Using this function will give you just the time difference in seconds:
<?php function relative_time( $input ) { return strtotime($input) - time(); } ?>
For example "1 minute" will return 60, while "30 seconds ago" will return -30
Valid relative time formats can be found at http://www.gnu.org/software/tar/manual/html_chapter/tar_7.html#SEC115
http://php.net/manual/en/function.strtotime.php