Display date from new date php
In PHP, you can use the date()
function to display the current date. Here are a few examples:
Displaying the current date in the format "YYYY-MM-DD"
echo date("Y-m-d");
Displaying the current date in the format "Month Day, Year"
echo date("F j, Y");
Displaying the current date in the format "Hour:Minute:Second"
echo date("H:i:s");
Displaying the current date in the format "Day, Month Year"
echo date("D, F Y");
You can also use the DateTime
class to display the date in a specific format:
$date = new DateTime();
echo $date->format("Y-m-d");
Note that the date()
function returns the current date and time, so if you want to display a specific date, you can use the strtotime()
function to convert a string to a timestamp, and then use the date()
function to format the date:
$dateString = "2022-07-25";
$date = strtotime($dateString);
echo date("Y-m-d", $date);