CODING ACADEMY

View Original

How to Use the DateTime Class in PHP

One of the things most developers face is dealing with time calculations and logging. In this lesson we play around with the DateTime class and see how useful it can be. 

We start off with a simple example where we set the $date variable to today's date (Line 3).

We then format the date into the Year-month-day format.

See this content in the original post

The nice thing about the DateTime class is that we can also do things like this:

See this content in the original post

...and this:

See this content in the original post

We can also perform calculations. We have already used this function in this tutorial.

See this content in the original post