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
date_default_timezone_set('Asia/Kolkata');
echo date("Y-m-d H:i:s"); // time in India
xxxxxxxxxx
$currentDate = date('Y-m-d'); // Example date format: '2021-09-20'
echo $currentDate;
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");
xxxxxxxxxx
//Your Country Time Zone: https://www.php.net/manual/en/timezones.php
date_default_timezone_get(Asia/Dhaka);
$dateYmd = date('Y-m-d');
echo "Current Year Month Day: $dateYmd";
//Current Year Month Day: 2022-01-14
$datehms = date('h:i:s');
echo "Current Hour Minute Second: $datehms";
//Current Hour Minute Second: 10:33:58
xxxxxxxxxx
phpCopy<?php
$DateAndTime = date('m-d-Y h:i:s a', time());
echo "The current date and time are $DateAndTime.";
?>