Help With Date

I have an issue where my credit card processor is in a time zone that is two hours ahead of my host. This causes me an issue when the day rolls over, it causes some problems for orders being placed. The current code I have in my page to insert the date into my order form is

<?php $today = date("Ymd"); print("\n"); ?>

I do not know a lot about coding, so I was wanting to just add two hours to the time, and output it like the code above. Any help would be greatly appreciated.

To just add (or deduct) number of hours from a date, you can do the following:

$h = 2; // hours to be added (to deduct use -2)
$today = date(“Ymd”,time() + 3600*$h);

But if you use date in multiple instances in your code, the more efficient solution would be to set desired timezone either in php.ini or within your script.

For PHP5 you can set timezone in the script:
[php] date_default_timezone_set(‘America/Los_Angeles’);

or in php.ini:

date.timezone = "America/Los_Angeles"

(here is the list of supported timezones:

And if you’re using PHP4, you can set timezone within your script like this:
[php] putenv(“TZ=US/Eastern”);

Sponsor our Newsletter | Privacy Policy | Terms of Service