In this article, we will see how to get the date & time using the date() & time() function in PHP, we will also see the various formatting options available with these functions & understand their implementation through the examples.
<?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") . "<br>"; // will show full text of day like monday echo "Year is " . date("y") . "<br>"; // will show last 2 digit of year eg 23 echo "Month is " . date("M") . "<br>"; // will show month short name e.g. Dec echo "Today is " . date("D") . "<br>"; // will show day short name e.g Mon echo "------------ // ------------" . "<br>"; date_default_timezone_set("Asia/Kolkata"); echo "The time is " . date("h:i:sa") . "<br>"; $day = date('w'); $week_start = date('m-d-Y', strtotime('-'.$day.' days')); $week_end = date('m-d-Y', strtotime('+'.(6-$day).' days')); ?>