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:

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




Home | Privacy Policy | Terms Of Use | Contact Us | Work At Home | Online Jobs | Smart Info | Online Jobs | Data Entry Jobs | Paid Surveys | Info | Info | Typing Jobs | Article Archive | Forum Posting Jobs