PHP Date Time

PHP Date Time

The following PHP code will return a PHP string variable that is the current server date and time:

 

Using PHP echo we can output the value of the above PHP string variable:

 

The above PHP code would display something similar depending on your server date/time:

2021-06-07 10:13:06

 

Let’s take a closer look at the original PHP code:

 

The PHP date() function has different parameters that can be used to output different formats of time and date as outlined as follows:

d: this is the day of the month using two digits ranging from 01 to 31
m: this is the month using two digits randing from 01 to 12
h: this is the hour of the day
i: these are the minutes
s: this represents seconds of a minute

 

Here is an example of adding hours to date/time using PHP:

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *