daniel244rock Posted August 24, 2006 Share Posted August 24, 2006 I have a rather large project written, taking in about 200 pages. Everything was working peachily. Then I switched hosts to be on a faster server, but the new server is in a different time zone than my old one. All my date() commands change to the next day at 10:00 PM, 2 hours ahead of schedule. Sadly, I didn't take this into account when I coded these pages or I could have put in a var that I could set and they'd all be updated.Is there a way I can subtract 2 hours from the server time sitewide? Or do I have to go though each page and strtotime("-2 hours") each one? Or is there another way to do this?Thanks much!Daniel Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted August 24, 2006 Share Posted August 24, 2006 The solution I used depended on:1. all calls for a timestamp were to the date(..) function.2. there were no other calls that looked like the date(..) pattern3. I had an INCLUDE file that was included in all routinesWhat I did was:1. a global change of my routines and changed all date(..) calls to my_date(..)2. in the INCLUDE file I added the following routine (you'll have to change it to suit your needs). First parm is display pattern, second one is offset to GMT (thanks to cHuAyW2o0o)[code]<?php function my_date($pattern, $offset) { // $offset = "2";// Hour for offset to GMT time zone goes here e.g. +7 or -4 return gmdate($pattern, time()+($offset * 3600)); }echo "Your current time now is : ". my_date("m/d/Y g:i:s A", 2);?> [/code]Hope this gets you on your way!Ronald 8) Quote Link to comment Share on other sites More sharing options...
daniel244rock Posted August 24, 2006 Author Share Posted August 24, 2006 HaHa!! That is perfect!Thank you so much for the excellent response. My scripts meet all the criteria you listed and the solution worked flawlessly. And so easy to update if I ever change hosts again.Thanks RonDaniel Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted August 24, 2006 Share Posted August 24, 2006 The good thing is: you don't have to change this when you change hosts! It uses an offset to the standard GMT time and that never changes (probably).Ronald 8) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.