This lesson will teach you how to display the current time, formating PHP's
timestamp, and show you all the various date arguments for reference
The date function always formats a timestamp, whether you
supply one or not.
What's a timestamp?
date function uses letters of the alphabet to represent various parts
of a typical date and time format. The letters we will be using in our
first example are:
The rest of the options will be studied later.
let's use those above letters to format a simple date.
Other characters like
a slash "/" can also be inserted between the letters to add additional
You would see something like:
The first argument of the date
function tells PHP how you would like your date and time displayed.
The second argument allows for a timestamp and is optional.
example below uses the mktime function to create a
timestamp for tomorrow. To go one day in the future we simply add one
to the day argument of mktime.
Note: These arguments are all optional. If
you do not supply any arguments the current time will be used to create
Notice that one letter at a time is used with the function date to
get the month, day and year.
For example the date("m")
will return the month's number 01-12.
that you know the basics of using PHP's date
function, you can easily plug in any of the following letters to format
your timestamp to meet your needs.
Try to create several
timestamps using PHP's mktime function and see what the outcome is.