|
| 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:
1327966210
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-01-2012
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-01-2012 06-02-2013 06-02-2012 07-02-2012 09-02-2012 06-01-2012
See also:
date()
time()
mktime()
gmdate()
microtime()
|
|