Date And Time Function In PHP
Last Updated : Jan 1, 2023
IN - PHP
In this tutorial we will show you the solution of date and time function in PHP, using date and time function we can display current date and time on webpage browser.
Those are related to one specific zone like asia or china so it depends on zone result will vary but time and date will be successfully printed on webpage.
For achieve result we must use timestamp, it is parameter can be used to set the timestamp for date and time that needs to be returned. By default it has current web server’s date and time as the timestamp.
Step By Step Guide On Date And Time Function In PHP :-
Here we will prints current date and time by time() and date() methods in php.
We needs to store the timestamp returned by the time() function in a variable.
It will be numeric value representing the number of seconds between the Greenwich mean time and the current server’s time. Date function specifying the timestamp.
<?php $ts = time(); echo(date("h:i:s A, F d, Y", $ts)); ?>
- A php script can be placed anywhere in the document. A php script starts with <?php and end with ?>.
- The default file extension for php files is “.php” and php statements end with ‘;’ semicolon.
- When we declaring variable in php we need to use ‘$’ symbol before variable name, here we declared variable ‘$ts’ for storing timestamp.
- It is must when we needs to get date and time collect timestamp then only we can achieve the result.
- Within date() function we defined pattern of time and date with timestamp as parameter. In pattern h – refers hour, I – refers minutes, s – refers seconds and A – refers for displaying uppercase antemeridian and post meridian (i.e AM or PM).
- F d,y are refers current date with help of timestamp variable ‘$ts’. We can get any format of date also we can display in php we have options for that.
- May be format only change results will same so we can choose any choice from php. We need to know only thing is how to handle that for achieve result.
- These functions used on database table for identification when those some of information collected or retrieved, modified likewise. Not only in database record when we design website some time we needs to use some other place also so we have to know how to handle date and time using php.
In conclusion we are able to get current date and timestamp using php. When work with php we need to create and process php files at server location and then we need to start the server before execute the program.
When we executing this program on browser it will prints current date and timestamp on webpage browser.
For achieve different formats of date and time we have to use those methods we will see about in future.
I hope this tutorial on date and time function in PHP helps you and the steps and method mentioned above are easy to follow and implement.