xxxxxxxxxx
$currentDate = date('Y-m-d'); // Example date format: '2021-09-20'
echo $currentDate;
xxxxxxxxxx
$today = date("F j, Y, g:i a"); // October 30, 2019, 10:42 pm
$today = date("D M j G:i:s T Y"); // Wed Oct 30 22:42:18 UTC 2019
$today = date("Y-m-d H:i:s"); // 2019-10-30 22:42:18(MySQL DATETIME format)
xxxxxxxxxx
<?php
echo "Today is " . date("Y/m/d") . "<br>";
echo "Today is " . date("Y.m.d") . "<br>";
echo "Today is " . date("Y-m-d") . "<br>";
echo "Today is " . date("l");
xxxxxxxxxx
<?php
echo "Today's date is :";
$today = date("d/m/Y");
echo $today;
?>
xxxxxxxxxx
date_default_timezone_set('Asia/Kolkata');
echo date("Y-m-d H:i:s"); // time in India
xxxxxxxxxx
phpCopy<?php
$Object = new DateTime();
$DateAndTime = $Object->format("d-m-Y h:i:s a");
echo "The current date and time are $DateAndTime.";
?>
xxxxxxxxxx
// Option 1: Using the date() function
$currentDate = date('Y-m-d');
echo $currentDate;
// Option 2: Using the DateTime object
$currentDate = new DateTime();
echo $currentDate->format('Y-m-d');
xxxxxxxxxx
# Current date
date_default_timezone_set('Asia/Kolkata');
echo date("Y-m-d H:i:s");
# Current Time
date_default_timezone_set("America/New_York");
echo "The time is " . date("h:i:sa");