FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


date() function





Sebaci
I have a problem with date() function. When it's 14:27 the function shows 7:27 on the site, no matter if I use g, G, h or H as an hour. I think it's something with a time zones, I'm in Poland
Scorpio
That is probably the server time..

Why dont you attempt using any of the numerous scripts at www.hotscripts.com to set your own time

or use a clock at www.clocklink.com
n0obie4life
I assume you are using time();

You have to add 1 hour to your time (I'm guessing Poland is in GMT+1, my geo skills are okay..Razz)

Put this in your PHP code

$time = time()+3600;
echo date("D M d, Y g:i a", $time);

We add 3600 to time because 3600 seconds = 1 hour. The time function returns the amount of seconds past the unix epoch (sp?) in GMT.
Sebaci
Ok, I will explain my problem again: I have this code:
Code:
$date = date("Y-m-d G:i");

But at 14:00 it shows 7:00. What to do?
Bondings
Sebaci wrote:
Ok, I will explain my problem again: I have this code:
Code:
$date = date("Y-m-d G:i");

But at 14:00 it shows 7:00. What to do?

As n0obie4life said, just replace it with:
Code:
$date= date("Y-m-d G:i",time()+3600);
Sebaci
Ok, I did it, but now when it's 18:00 it shows 12:00.
Bondings
Sebaci wrote:
Ok, I did it, but now when it's 18:00 it shows 12:00.

Then add 6*3600 to it.
Code:
$date= date("Y-m-d G:i",time()+(7*3600));
Stubru Freak
Bondings wrote:
Sebaci wrote:
Ok, I did it, but now when it's 18:00 it shows 12:00.

Then add 6*3600 to it.
Code:
$date= date("Y-m-d G:i",time()+(7*3600));


I think
Code:
$date= gmdate("Y-m-d G:i",time()+3600);

works too, but this will still return the right time if you move your script to another server.
Sebaci
It worked. Thank you guys Very Happy
n0obie4life
stubru_freak - Adding 3600 seconds is only 1 hour. We have people living more than 1 hour away Rolling Eyes.

Anyway, topic resolved.

-close-
Daniel15
n0obie4life wrote:
stubru_freak - Adding 3600 seconds is only 1 hour. We have people living more than 1 hour away Rolling Eyes.

Anyway, topic resolved.

-close-


stubru_freak is right. gmdate() returns the date at GMT, and he added 1 hour to the time, so the result is GMT+1. This is the correct way to use a different time zone in PHP, as it doesn't rely on the server's time zone.

Sure, the code with date() will work on the FriHost server, but what if you move your script onto another server with a different time zone? With date(), you'd need to change the amount you add to reflect the new difference, whereas with gmdate(), you wouldn't need to.
Related topics
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Support and Web Hosting -> Web Hosting Support

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.