What Will I Learn?
- You will learn to make auto date according to server time
Requirements
- You must have a localhost server to try it out WAMP/MAMP/LAMP/XAMP or any other PHP/MYSQL STACK
Download Xampp https://www.apachefriends.org/download.html
Difficulty - Basic
Tutorial Contents
in this tutorial I will discuss how to display the date into a web page. Date which will be displayed adjust the server time, not the time in the client. This matter caused PHP is server side programming. - Example : write the following code in the text editor then save it on localhost with date.php name
echo date("m/d/y");
Code Explanation
Functiondate ()
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 is
We can change the date format in the form of 20-01-18 with the command
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)
- Example : Write the following code in the text editor then save it with the name mktime.php then save it and run it on localhost
$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). "";
Results :
- Okay, just a few lessons today, and follow me on for the next tutorial
Curriculum
there is no tutorial related to this post
Posted on Utopian.io - Rewarding Open Source Contributors
good to see more n more programming stuff coming up on steemit. keep posting more
ha ha, thanks, I will try to invite everyone to learn programming :)
you are welcome
Clean tutorial, well done. Keep it up.
thanks guys :)
Your contribution cannot be approved because it is not as informative as other contributions. See the Utopian Rules. Contributions need to be informative and descriptive in order to help readers and developers understand them.
You can contact us on Discord.
[utopian-moderator]