date() formats a Unix timestamp using the active default timezone. Set or verify the timezone before formatting when the application depends on a specific region.
date_default_timezone_set('Asia/Kolkata');
echo date('Y-m-d H:i:s');For object-oriented date calculations, prefer DateTimeImmutable/DateTime rather than manually manipulating formatted strings.
<?Php
echo date("m/d/y"); // Today's date in m/d/y format
echo "<br>"; // Line break
echo date("d/m/y : H:i:s"); // Date/month/year Hour Minutes Second
echo "<br>"; // Line break
echo date("F j, Y, g:i a"); // today's date with time
echo "<br>"; // Line break
echo date("F j, Y, g:i a",time()) // same as above
?>
PHP can generate today date and time in different formats.
Here is a simple date command in PHP to display today date.
date("date format",[timestamp])
Here is a sample output using m/d/y format: 09/30/26
echo date('M');
The output is here.
Sepecho date('M',strtotime("first day of last month"));Augecho date('M',strtotime("last day of -2 month"));Julecho date('l');
The output is here.
Wednesdayecho date('d');
The output is here.
30
echo date('U');
Output is here ( refresh this page and see the change )
1790726703 This is same as output of time() function. $tdtp=date("Y-m-d H:i:s",time());
Here is the output ( refresh this page and see the change ) 2026-09-30 00:05:03
Creating Date object by using date and time interval
Date as string by using strtotime()
PHP Date Functions
Date formats for Date()
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
| clyf | 29-03-2012 |
| 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 | |
| nobby | 10-06-2014 |
| 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 | |