How do I subtract from getdate()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ross
Forum Newbie
Posts: 9
Joined: Thu Feb 16, 2006 1:14 pm

How do I subtract from getdate()

Post by Ross »

I am working in CST and my website is for this timezone. I am using the the function getdate() to make a current date to test database dates against.

My problem: the date I receive from getdate() is two hours ahead of CST. Can someone help me understand how to subtract two hours? My code for the variable looks like this:

Code: Select all

$curDate = date('Y-m-d', mktime(getdate()));
I read there is a function "date_default_timezone_set()" but I am not running php5 so I cannot utilize it. Is there a way to get this function working? (I don't have control over the webserver so I cannot actually load a new version of php but I have read of something called "php_compat". Any help would be appreciated. Thanks

Ross
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$curDate = date('Y-m-d', gmmktime() + ($timezone * 60 * 60));
where $timezone is your timezone offset from GMT. For CST that's GMT-6. So $timezone would be -6.
Post Reply