PHP

 Home  Computers & Internet  Web Programming PHP
What is PHP?
Echo
Comments
Variables
Constants
Data Types
number_format()
Character Strings
Mathematical Operators
Comparison Operators
Logical Operators
Joining Strings
explode()
implode()
strtolower()
strtoupper()
strlen()
ucfirst()
ucwords()
strrev()
str_replace()
str_repeat()
trim()
strip_tags()
addslashes()
stripslashes()
strpos()
strrpos()
nl2br()
isset()
unset()
empty()
POST
GET
If Statements
If Else Statements
Elseif Statements
Switch Statements
For Loops
While Loops
Do While Loops
Foreach Loops
File Create
File Open
File Read
File Write
File Delete
fgets()
file_get_contents()
Date & Time
$_SERVER
Sessions
Cookies
Arrays

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()




Home | Privacy Policy | Terms Of Use | Contact Us