Creating Timestamps with mktime()

You can already get information about the current time, but you cannot yet work with arbitrary dates. mktime() returns a timestamp you can then use with date() or getdate(). mktime() accepts up to six integer arguments in the following order:

hour
minute
second
month
day of month
year

Listing 16.3 uses mktime() to get a timestamp that we then use with the date() function.

Listing 16.3. Creating a Timestamp with mktime()
 1: <!DOCTYPE html PUBLIC
 2:   "-//W3C//DTD XHTML 1.0 Strict//EN"
 3:   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 4: <html>
 5: <head>
 6: <title>Listing 16.3 Creating a Timestamp with mktime()</title> 7: </head> 8: <body> 9: <div> 10: <?php 11: // make a timestamp for 1/5/04 at 2.30 am 12: $ts ...

Get Sams Teach Yourself PHP in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.