O'Reilly logo

Wicked Cool PHP by Brian Ward, William Steinmetz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

#46: Getting the Timestamp of a Date in the Past or Future

Now that you know how to get the current timestamp, let's explore how to determine some other timestamps close to the current time. For example, you can extract yesterday's timestamp or, say, next Friday's. There are two general methods for finding these values:

  • Determining the timestamp based on a string

  • Determining the timestamp from date values (which can be a bit trickier)

Creating Timestamps from a String

The strtotime() function can sometimes be a PHP programmer's best friend. Just as its name suggests, strtotime() generates a timestamp from an English date-phrase, such as April 1 or Friday. These strings can be either relative to the current date or absolute. Table 6-2 outlines some ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required