CODING ACADEMY

View Original

How to Use strtotime() in PHP

Probably one of the most useful time/date related functions in PHP is strtotime(). In this lesson I will show you some of the basic uses for this incredibly useful function.

Using the function is quite straightforward as we can pass in a multitude of strings and the function will parse each of them.

For example:

See this content in the original post

The function returns a Unix timestamp, which we can then operate on further. The output from the above code is:

See this content in the original post

We can use other functions on the Unix output and turn this into full dates as follows:

See this content in the original post

I find this function incredibly useful when dealing with date and time database entries.

If you would like to learn more about PHP then enrol in the PHP for Beginners course.