date(): PHP Date Today with time

<?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
?>
Date Today in PHP 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: 05/19/24

Use of PHP timestamp in the date function is optional. If timestamp is not given then by default it takes the current timestamp or time().

To display the date in above format we have used the date format like this
date("m/d/y")

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 formatting 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.
May 19, 2024, 5:46 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.
May

Displaying Last Month

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

Displaying 2nd Last Month

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

Present Day of the Week

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

Present Day of the Month

echo date('d');
The output is here.
19

Time elapsed in seconds since Unix Epoch

echo date('U');
Output is here ( refresh this page and see the change )
1716140771
This is same as output of time() function.
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 ( refresh this page and see the change )
2024-05-19  17:46:11
Creating Date object by using date and time interval Date as string by using strtotime() PHP Date Functions Date formats for Date()
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    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

    Post your comments , suggestion , error , requirements etc here





    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer