 Very often, the servers hosting our scripts are not in the same time zone as our target visitors. In order to use the current time and date, the server info must first be recalculated adding (or subtracting) the time difference.
Here is a simple script that illustrates how to achieve the change. You can easily add or subtract any amount of time, ranging from 1 second to multiple years:
<?php
//Today's date and time
echo "Today's date: " . date("j-n-Y") . "<br>";
echo "Current time: " . date("h:i:s") . "<br>";
//Add to the current date and time using mktime - store in a variable
$now= date("j-n-Y h:i:s", mktime(date("h"), date("i"), date("s"), date("n"), date("j"), date("Y")));
//By arithmetically adding to the separated values, mktime calculates the new date info
$altered= date("j-n-Y h:i:s", mktime(date("h")+1, date("i"), date("s"), date("n"), date("j")+1, date("Y")));
echo "<br>NOW, using mktime for timestamp: <br>" . $now . "<br>";
echo "<br>NOW + 1 day + 1 hour: <br>" . $altered . "<br>";
?>
In this example, I’m using the mktime function to recalculate the time / date and the date function to format the output. The code prints the current date and time, then stores in a variable the result of adding one hour and one day.
You can personalize this code to fit your needs and then save it to a file. Afterwards, it will be easy to include the file in your scripts and use the $altered variable every time you are required to output the current time / date.
Author : Esopo, Read 4855 times, Comments: 1| Rating : |           | | Thursday, 11. August 2005 |
Add new comment/Comments
Your rating : Poor     Excellent |
  Are your scripts homeless? NetBulge.com is devoted to web development. If you are too, then this is the site to house your best scripts and articles. Think about it: exposure, knowledge sharing and free rent.
Join us!
  Featured * The Notepad on steroids. Quickness and simplicity, the Notepad’s two most acclaimed features are the core of this little editor; except Notepad2 goes the extra mile to provide syntax highlighting, brace matching, auto indent, rectangular selection, etc. With this tool around, there is no reason to have the original Notepad on your PC. (Source code available) If you are a web developer, this link is a must in your quick-links bar. A visit to this site will clear even the most diligent creative-block. http://www.k10k.net/ |