Page 1 of 1

Date Format

Posted: Thu Mar 19, 2009 9:07 pm
by Strobilus
Hi,

The default date format in version 1.6 is currently American style (month date, year). I see this is hardcoded in gbook.php on line 749 ("F j, Y").

Not all of us are American! :)

The normal style in the UK (and elsewhere) is date month year ("j F Y"). It would be very useful to be able to set this as an option in settings.php rather than having to change the code in gbook.php (the more you have to change gbook.php the more of a pain it is to upgrade when the time comes).

Just a suggestion from us UK users ... :wink:

Many thanks for an excellent script!

David

Posted: Thu Mar 19, 2009 10:02 pm
by Henrie
I know what you mean.

I have done this a long time ago already in my xhtml version. Although it has stuck on GBook code version 1.5 now, no time to upgrade it. Maybe i should have a conversation with Klemen sometime to have some things i have included (which were all suggested in the forum here) included in the normal version (i would not have to maintain my own separate version than anymore :D )

Greetings,
Henrie

Posted: Fri Mar 20, 2009 12:46 am
by Strobilus
Precisely, Henrie! Yes, it's easy enough to change the code in gbook.php but then, when the time comes to upgrade, it would be a real pain trying to remember all the tiny little changes you've done. It would be so much easier having all the options together in settings.php.

I can remember years ago doing so many modifications to the code for a PHP forum that I couldn't stand the thought of upgrading. I kept putting it off.

Nowadays, unless I can find an off-the-shelf PHP script that already suits what I need, I tend to write my own from scratch. A lot of work - and some of my coding is pretty primitive - but at least I know what's in there and I just upgrade it as I go along!

---------------------------------

For this GBook script I've only changed settings.php, language.inc.php, header.txt, footer.txt and style.css to get the look I want.

I haven't touched gbook.php yet. I can live with the American date format for now. I'll keep my fingers crossed that Klemen might put in a date format option in an upgrade. :wink:

Posted: Fri Mar 20, 2009 4:43 pm
by Klemen
Added on my "to do" list, thanks for the suggestion.

Posted: Sat Mar 21, 2009 3:00 pm
by Strobilus
Many thanks, Klemen. That would be brilliant!

This really is a great script. Works flawlessly.

Posted: Sat May 15, 2010 5:20 pm
by Annie
I'm using version 1.7 and would like to know how you change the date format to day, month, year.

I've found this bit of code starting on line 873 but am not sure what to do.

Code: Select all

    /* Everthing seems fine, let's add the message */
	$delimiter="\t";
	$m = date('m');
	if (isset($lang['m'.$m]))
	{
		$added = $lang['m'.$m] . date(" j, Y");
	}
	else
	{
		$added = date("F j, Y");
There' also the following starting on line 517 but, again, I don't know if I have to change this.

Code: Select all

	global $settings, $lang;
	$secnumber.=$settings['filter_sum'].date('dmy');
I'd also like to know if it's possible to offset the time as my server isn't in my country and the date is sometimes incorrect because of the time difference.

Posted: Sat May 15, 2010 6:01 pm
by Henrie
Hallo Annie,

See the following topic: viewtopic.php?t=2636
It starts with question for date format in version 1.6 but towards the end it is about version 1.7.
I hope it helps, if not, let us know.

Greetings,
Henrie

Posted: Sat May 15, 2010 9:23 pm
by Annie
Hello Henrie,

Thank you for the link to the instructions. I now have the date and time formatted how I want them to appear but I still have the problem that the time shows 5 hours behind because my server is in America and I'm in England. Is there a way I can adjust the offset time? I'm not really all that familiar with php.

Great script, by the way.

Posted: Sun May 16, 2010 5:52 am
by Henrie
Hello Annie,

Sorry, i overread that question. Only expected on question in the message.

You have not given us information about the server (no phpinfo.php file link). But if your server is running PHP 5.1.0 or newer you could add

Code: Select all

date_default_timezone_set('America/Los_Angeles');
Place it just below

Code: Select all

/* Everthing seems fine, let's add the message */
which is found on line 873 in GBook version 1.7

Greetings,
Henrie

Posted: Sun May 16, 2010 10:05 am
by Annie
Thanks for the reply Henrie.

Unfortunately, it seems my server is only running php version 4.4.9 and this method didn't work. Is there anything else I can do to get the time right please? I want to run the guestbook on London time.

Posted: Sun May 16, 2010 11:18 am
by Henrie
Hello Annie,

That is a really old PHP version. You should tell your hosting provider to upgrade to a newer PHP version. It is really unsafe to use such an old PHP version.
But untill they do you are stuck with it.
You could do the following to manually increase the time.
Change the code in Gbook 1.7 starting at line 873

Code: Select all

    /* Everthing seems fine, let's add the message */
	$delimiter="\t";
	$m = date('m');
	if (isset($lang['m'.$m]))
	{
		$added = $lang['m'.$m] . date(" j, Y");
	}
	else
	{
		$added = date("F j, Y");
	}
to

Code: Select all

    /* Everthing seems fine, let's add the message */
	$mytime = time() + (5 * 60 * 60); //set my time, in this case increase time with 5 hours * 60 mins * 60 secs
	// time is returned in seconds, so increase in seconds: days; 24 hours; 60 mins; 60secs. To increase 7 days is time() + (7 * 24 * 60 * 60);
	$delimiter="\t";
	$m = date('m', $mytime);
	if (isset($lang['m'.$m]))
	{
		$added = $lang['m'.$m] . date(" j, Y", $mytime) . " at " . date("G:i", $mytime);
	}
	else
	{
		$added = date("F j, Y", $mytime);
	}
And you are right about the script, it is great. Klemen did a good job at writing it.

Greetings,
Henrie

Posted: Sun May 16, 2010 2:48 pm
by Annie
Many thanks Henrie, it worked a treat.

Annie

Re: Date Format

Posted: Sun Oct 09, 2011 11:49 pm
by cAdams
WAHOO!!! the second option worked for me too :)

Re: Date Format

Posted: Mon Nov 26, 2012 7:45 pm
by cAdams
i so i THOUGHT the time/date formatting worked for NZ time but it appears not

while the time is correct with 'my time' set to 12 hrs ahead, with the Mon-Sun in the language.php as 0-6, 27 November 2012 comes up as a Monday

over here in NZ it's Tuesday!

renumbering the language.php Mon-Sun didn't make any difference, nor did increasing gbook.php 'mytime' offset

but have now edited the coding to remove the week day, removed the wek days from the language.php and added an 'l' to the date code so the correct day is now displayed :D

Re: Date Format

Posted: Mon Nov 26, 2012 9:07 pm
by Henrie
It has been to long ago since I played with this. And I do not have to time to dive into it again now. But maybe the php manual page about the date function can help you, http://www.php.net/manual/en/function.date.php

And than apply that to the code in gbook.php starting at line 873.