Minhea Posted July 14, 2005 Posted July 14, 2005 Hello everyone! I have a problem with date and time of my new Guestbook script. Here is my Guestbook: http://shinydust.net/guestbook The problem is Mysql timezone, which results in function "datetime" in MySql Guestbook database, and appears near every entry. I suppose the reason is that your server (mine is Server92) are located in USA, while I'm italian: so default timezone is wrong for Italy. For example: as you can read, in last "Sciapy" entry date and time displays now 13/07/2005 23:53. That's because I've changed the time manually in the database. ^_^'' First, when she posted in my Guestbook, default date and time was: 13/07/2005 17:53 I'm sure it's your timezone server. But in my Guestbook I'd like to display GMT date and time for Europe, particularly italian date and time. How can I do this? Is there a way to change timezone in Cpanel or MySql database? I've searched for an option, but didn't find nothing. Otherwise, is there a special timezone table to add in the database, or a special code to display in my pages which modifies default timezone with the italian one? Please, help me. Many thanks in advance, bye bye! Quote
TCH-Andy Posted July 14, 2005 Posted July 14, 2005 Hi, The server time is in the time zone which is correct for the server. If your time zone is different, then you need to modify the code to allow for that. Most php code allows you to set a time zone in the admin / config (in the same way as you can set your time zone on this server, so it's correct for you). I don't think the guestbook you are using allows for that, so you will need to look in the source code where it gets the time (template-tags.php), and modify the line to take account of the different time zone for you. For guestbook I think you will need to add "3600*X" where X is the numbers of hours shifted in time zone (6 in your case). Alternatively you may be able to use the "putenv" function to set the time zone in php for that sccript. Quote
Minhea Posted July 14, 2005 Author Posted July 14, 2005 Thanks for your fast and nice reply! I'll try to modify the PHP code, as you suggested me. Hope to manage it! ^_^'' I'll let you know if there are other problems. Bye, have a nice day! :* Minhea Quote
Minhea Posted July 14, 2005 Author Posted July 14, 2005 (edited) Uhm... I think I'm really confused. This is more complicated then I expected. In template-tags.php I've found this datetime string: function entry_time($format='F jS, Y g:i A') { global $entry; echo date($format, strtotime($entry['date'])); Is this what is needed to me, the right place to add the timezone difference? And where do I have to add that "+6*3600" string? I've tried to add it after function $format, then tried to post. But nothing changed at all. o_O' Someone help me, please... I'm only a PHP novice. Thank you! EDIT: I've modified the string in this way: function entry_time($format='F jS, Y g:i A') { global $entry; echo date($format, strtotime($entry['date']))+3600*6; Something strange happened: now all my dates appeared something like this 21607 Creepy. Sigh! Edited July 14, 2005 by Minhea Quote
TCH-Don Posted July 14, 2005 Posted July 14, 2005 Try function entry_time($format='F jS, Y g:i A Z21600') { global $entry; echo date($format, strtotime($entry['date'])); Z is offset for time zone 21600 is 3600x6 Zvalue to make the time zone more Z-value to make the time zone less I think that will work. Quote
TweezerMan Posted July 14, 2005 Posted July 14, 2005 Minhea, you almost had it! The time offset you're trying to add needs to be inside the outermost parenthesis: >echo date($format, strtotime($entry['date'])+3600*6); Quote
Minhea Posted July 15, 2005 Author Posted July 15, 2005 *__* Thank you so much, both of you, for replying me! I think I should have understand... I' ll try your script later, then I'll told you if it works in my GB. Thanks again! Quote
Minhea Posted July 15, 2005 Author Posted July 15, 2005 WEEEH... David, you were right: I've modified the string as you told me, and now the date is the italian one!!! I'm happy! Thank you so much! Bye everyone, have a nice week-end! Quote
falafel Posted August 17, 2005 Posted August 17, 2005 Hi! I have a problem similar to Minhea. I live in Sweden and i'm reconfiguring a guestbook. I use MySQL and PHP. This is the code: >Written by <strong><?php entry_smart_name(); ?></strong> on <?php entry_time('F jS, Y'); ?> at <?php entry_time('g:i A'); ?> And this is what it print out: >Written by Tiffany on August 17th, 2005 at 2:35 PM Sure, that's exactly what it should print out. But since i live in sweden that date-syntax is wrong. I want it to print out lite this: >Skrivet av Tiffany den 7e Augusti, 2005 klockan 14:35 PM I need all the help i can get, my PHP and MySQL skills aren't very good. Thanks in advance /Henrik Quote
TCH-Thomas Posted August 17, 2005 Posted August 17, 2005 Welcome to the forum, Henrik. Nice to see another Swede in the forum. Unfortunately I don´t know the answer to this but hang in there and someone will know the answer. Quote
TCH-Andy Posted August 17, 2005 Posted August 17, 2005 Welcome to the forum Instead of the line; >Written by <strong><?php entry_smart_name(); ?></strong> on <?php entry_time('F jS, Y'); ?> at <?php entry_time('g:i A'); ?> try >Skrivet av <strong><?php entry_smart_name(); ?></strong> den <?php entry_time('F jS, Y Z21600'); ?> klockan <?php entry_time('g:i A Z21600'); ?> The alternative route, I think, is to use ><?php setlocale('LC_TIME','swedish'); ?> before this line. Do you also want the month to be in Swedish? Quote
stevevan Posted August 17, 2005 Posted August 17, 2005 Welcome to the forums! I see Thomas has found a new friend! Quote
falafel Posted August 17, 2005 Posted August 17, 2005 Thank you guys! Welcome to the forum Instead of the line; >Written by <strong><?php entry_smart_name(); ?></strong> on <?php entry_time('F jS, Y'); ?> at <?php entry_time('g:i A'); ?> try >Skrivet av <strong><?php entry_smart_name(); ?></strong> den <?php entry_time('F jS, Y Z21600'); ?> klockan <?php entry_time('g:i A Z21600'); ?> The alternative route, I think, is to use ><?php setlocale('LC_TIME','swedish'); ?> before this line. Do you also want the month to be in Swedish? <{POST_SNAPBACK}> When i tried: >Skrivet av <strong><?php entry_smart_name(); ?></strong> den <?php entry_time('F jS, Y Z21600'); ?> klockan <?php entry_time('g:i A Z21600'); ?> It gave me: Skrivet av Tiffany den August 17th, 2005 720021600 klockan 12:35 PM 720021600 So that didn't work at all I also tried: >Skrivet av <strong><?php entry_smart_name(); ?></strong> den <?php setlocale('LC_TIME','swedish'); ?><?php entry_time('F jS, Y'); ?> klockan <?php entry_time('g:i A'); ?> But it didn't make any difference att all from how it were before. This is how the whole file looks like; ><div class="entry" id="<?php entry_id(); ?>"> <p class="entrymetadata"> Skrivet av <strong><?php entry_smart_name(); ?></strong> den <?php entry_time('F jS, Y'); ?> klockan <?php entry_time('g:i A'); ?> </p> <?php entry_comment(); ?> </div> Any ideas? Quote
TweezerMan Posted August 17, 2005 Posted August 17, 2005 Welcome to the forums, Henrik! Using setlocale('LC_TIME','swedish'); localizes output only of the strftime() function, not the date() function. In order to localize your dates, you'd need to alter the entry_time() function to something like this: >function entry_time($format='%B %e, %Y %H:%M') { global $entry; setlocale(LC_TIME,'swedish'); echo strftime($format, strtotime($entry['date'])+3600*6); } Then you could use code like the following: >Skrivet av <strong><?php entry_smart_name(); ?></strong> den <?php entry_time('%e %B, %Y'); ?> klockan <?php entry_time('%H:%M'); ?> ...which should produce the following output: Skrivet av Tiffany den 17 augusti, 2005 klockan 20:35 That's about as close as I could make it to what you want without a significant amount of programming. Hope this helps... Quote
carbonize Posted August 21, 2005 Posted August 21, 2005 Wonder why nobody suggested the easiest fix for Minhea's problem which is to change date() to gmdate() Quote
TCH-Andy Posted August 21, 2005 Posted August 21, 2005 Because you weren't along quick enough to suggest it Quote
carbonize Posted August 21, 2005 Posted August 21, 2005 lol I was in the Canaries enjoying a much deserved vacation Quote
TweezerMan Posted August 21, 2005 Posted August 21, 2005 I thought it was because the timezone was being adjusted for local Italy time, which is GMT+1. gmdate() wouldn't have been any help for that. Quote
carbonize Posted August 21, 2005 Posted August 21, 2005 You adjust the time/date in gmdate() exactly as you would in date() it's just that you know exactly the timezone you are adjusting from. Quote
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.