What Will I Learn?
Requirements
<?php
echo date("m/d/y");
?>date () is used to display the current date (according to server time). Suppose that it is the 20th January 2018, then the view from the script above isWe can change the date format in the form of 20-01-18 with the command
<?php
echo date("d-m-y");
?>
results :
So what if we want to display a date in the next 2 days? Here's the code
<? php
$ duaharilagi = mktime (0, 0, 0, date ("m"), date ("d") + 2, date ("y"));
echo "Two more days is the date". date ("d / m / y", $ duaharilagi);
?>
re-edit date.php and replace with the code above then save
Results :
Code Explanation :
The mktime () function is used to create a timestamp, with the syntax:
mktime (hour, minute, second, month, day, year)
<?php
$tomorrow =mktime (0, 0, 0, date ("m"), date ("d") + 1, date ("Y"));
$ lastmonth = mktime (0, 0, 0, date ("m") - 1, date ("d"), date ("Y"));
$ nextyear = mktime (0, 0, 0, date ("m"), date ("d"), date ("Y") + 1);
echo "Tomorrow is the date". date ("d / m / y", $ tomorrow). "
";
echo "A month ago is the date". date ("d / m / y", $ lastmonth). "
";
echo "Another year is the date". date ("d / m / y", $ nextyear). "
";
?>