![]() |
Home
iRate! IceMelon IM Tutorials Headlines CoolSites PHP Functions |
Most Referenced Functions » google_pagerank() » preg_replace() » imagecreatefrompng() » site_pageranks() » imagepng() » imagedestroy() » imagestring() » imagecolorallocate() » htmlentities() » fopen() » preg_match() » header() » getimagesize() » htmlspecialchars() » session_start() » ob_start() » strstr() » ob_flush() » preg_match_all() » strpos() » flush() » setcookie() » str_replace() » array2vars() » nl2br() » preg_split() » ereg() » urlencode() » ereg_replace() » readgzfile() Become a sponsor for $15/month. Link is sitewide - PR5 homepage, 20+ PR4 pages, 90+ PR3 pages. Email dave[AT]icemelon[D0T]c0m. |
PHP Functions
Function: strtotime (PHP 3 >= 3.0.12, PHP 4, PHP 5) strtotime -- Parse about any English textual datetime description into a Unix timestampDescriptionint strtotime ( string time [, int now] )The function expects to be given a string containing a US English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT), relative to the timestamp given in now , or the current time if none is supplied. This function will use the TZ environment variable (if available) to calculate the timestamp. Since PHP 5.1.0 and if the TZ variable isn't set, the date.timezone ini configuration option will be used. If none of these are available, "GMT" is assumed. Parameters
time The string to parse, according to the GNU Date Input Formats syntax nowThe timestamp used to calculate the returned value Return ValuesReturns a timestamp on success, FALSE otherwise. Previous to PHP 5.1.0, this function would return -1 on failure. ChangeLog
Version Description 5.1.0 It now returns FALSE on failure, instead of -1 . Added the date.timezone ini option.
Examples
Example 1. A strtotime() example <?php echo strtotime("now"), "\n"; echo strtotime("10 September 2000"), "\n"; echo strtotime("+1 day"), "\n"; echo strtotime("+1 week"), "\n"; echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n"; echo strtotime("next Thursday"), "\n"; echo strtotime("last Monday"), "\n"; ?>
Example 2. Checking for failure <?php $str = 'Not Good'; // previous to PHP 5.1.0 you would compare with -1, instead of false if (($timestamp = strtotime($str)) === false) { echo "The string ($str) is bogus"; } else { echo "$str == " . date('l dS of F Y h:i:s A', $timestamp); } ?> NotesWarning In PHP 5 up to 5.0.2, "now" and other relative times are wrongly computed from today's midnight. It differs from other versions where it is correctly computed from current time. Note: The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.) Additionally, not all platforms support negative timestamps, therefore your date range may be limited to no earlier than the Unix epoch. This means that e.g. dates prior to Jan 1, 1970 will not work on Windows, some Linux distributions, and a few other operating systems. Related Function(s) |