|
| HOW TO USE THE strtotime() FUNCTION IN PHP
The strtotime() function makes it easy for you to work out dates by taking, as it's argument, selected English phrases.
The general format of the strtotime() function is as follows:
strtotime("English Phrase");
This returns a Unix Timestamp.
Example:
echo strtotime("1 week ago");
This outputs:
1230638503
This Unix Timestamp is not very useful to us as you can see. To get a human readable formatted form, combine strtotime() function with the date() function as follows:
echo date("d-m-Y", strtotime("1 week ago"));
This outputs:
30-12-2008
More examples:
echo date("d-m-Y", strtotime("last week"));
echo date("d-m-Y", strtotime("next year"));
echo date("d-m-Y", strtotime("now"));
echo date("d-m-Y", strtotime("tomorrow"));
echo date("d-m-Y", strtotime("next Thursday"));
echo date("d-m-Y", strtotime("1 month ago"));
These will output:
30-12-2008 06-01-2010 06-01-2009 07-01-2009 08-01-2009 06-12-2008
See also:
date()
time()
mktime()
gmdate()
microtime()
|
|