PHP Date Today with time

Date Today in PHP PHP can generate today date and time in different formats for use in different applications. PHP date function returns date with a given format along with time. Here is a simple date command in PHP to display today date.
date("date format",[timestamp])

The output of the above command is: 07/15/18

Use of PHP timestamp in the date function is optional. To display the date in above format we have used the date format like this

This will format the display to month / day / year format. We can change the display to any other format we want with use of different characters to format the string. You will get a list of such characters used for formating the date is listed at the end of this page.

Let us display the todays date with the present time using the date format characters in a better way.
July 15, 2018, 7:45 pm

Refresh your browser window to see how the time is changing. Here is the code used to display the above date and time.
date("F j, Y, g:i a")

Displaying Present Month

echo date('M');
The output is here.

Displaying Last Month

echo date('M',strtotime("first day of last month"));

Displaying 2nd Last Month

echo date('M',strtotime("last day of -2 month"));

Present Day of the Week

echo date('l');
The output is here.

Present Day of the Month

echo date('d');
The output is here.
You can try more such outputs by using different date formats

Format for MySQL datetime field

MySQL datetime field stores date with time. Here is the format required to store data in this field.
$tdtp=date("Y-m-d  H:i:s",time());
Here is the output
2018-07-15  19:45:02

Subscribe to our mailing list

* indicates required
Subscribe to plus2net
Visitors Rating
Your Rating


More On Date Object


i want u to send me the scripts in php of how to recover a forgotten password, how to create a form with a photo attached to it, just reply to my email, thanx


the article was helpfull but still the time i get on my page is one hour ahead any idea on how to reduce it so as i can get the appropriate time?

thank you in advance

Post Comment This is for short comments only. Use the forum for more discussions.

Subscribe to our mailing list

* indicates required
Subscribe to plus2net
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2018 All rights reserved worldwide Privacy Policy Disclaimer