Google News
logo
PHP Program to Format today's date in several ways
In the following example of PHP program to format today's date in several ways :
Program :
<?php
// Get today's date
$date = date("Y-m-d");

// Print the date in various formats
echo "Today's date is $date<br>";
echo "Formatted date (1): " . date("l, F jS Y") . "<br>";
echo "Formatted date (2): " . date("F j, Y") . "<br>";
echo "Formatted date (3): " . date("m/d/Y") . "<br>";
echo "Formatted date (4): " . date("d-m-Y") . "<br>";
?>
Output :
Today's date is 2023-05-01
Formatted date (1): Sunday, May 1st 2023
Formatted date (2): May 1, 2023
Formatted date (3): 05/01/2023
Formatted date (4): 01-05-2023
This program first gets today's date using the `date()` function and stores it in the `$date` variable. It then prints out the date in various formats using different format strings with the `date()` function.

Note that the exact output will depend on the current date and time zone settings.