The PHP Strtotime Function

The PHP Strtotime Function
The PHP strtotime function is used to store a Unix timestamp as a value of a variable. But what makes this PHP function so versatile is the list of "human" keywords and abbreviations that you can use to create a specific timestamp to store in that variable. Let's take a look at the code and then the list of keywords and abbreviations.

$variable_name = strtotime("keyword or abbreviation");

<?php
$birthday = strtotime("June 6 2000");
?>

As you can see, the syntax for the strtotime function is straight forward. It begins with the variable name followed by an equal sign. Then inside the parenthesis and quotation marks is where the magic happens. You can use any of the keywords and abbreviations from the list below to create a timestamp for the variable. You can also use combinations of keywords and abbreviations. For the example above, the value stored in the $birthday variable will be my niece's birthday which is June 6, 2000.

Below is the list of keywords and abbreviations. Try replacing my example with various combinations from the list below.

Units of time such as
    year, month, week, day, hour, minute, second, am, pm, fortnight
English words for time such as
    ago, now, last, this, next, tomorrow, yesterday
Minus and Plus - and +
Numbers 1, 2, 3 . . .
Time Zones
    gmt, pdt, akst
Name of the months and abbreviations
Day of the week and abbreviations





This site needs an editor - click to learn more!



RSS
Editor's Picks Articles
Top Ten Articles
Previous Features
Site Map





Content copyright © 2023 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.