Date Format

Everything related to GBook PHP guestbook
Post Reply
Strobilus
Posts: 3
Joined: Thu Mar 19, 2009 8:48 pm

Date Format

Post 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
Henrie
Posts: 1095
Joined: Sun Aug 14, 2005 8:57 pm

Post 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
I do not monitor the Gbook forums regularly anymore since I do not use the Gbook script myself anymore for a long time. But it helped me a lot in learning to understand php.
Strobilus
Posts: 3
Joined: Thu Mar 19, 2009 8:48 pm

Post 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:
Klemen
Site Admin
Posts: 10116
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Added on my "to do" list, thanks for the suggestion.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Strobilus
Posts: 3
Joined: Thu Mar 19, 2009 8:48 pm

Post by Strobilus »

Many thanks, Klemen. That would be brilliant!

This really is a great script. Works flawlessly.
Annie
Posts: 20
Joined: Sat May 15, 2010 5:08 pm

Post 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.
Henrie
Posts: 1095
Joined: Sun Aug 14, 2005 8:57 pm

Post 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
I do not monitor the Gbook forums regularly anymore since I do not use the Gbook script myself anymore for a long time. But it helped me a lot in learning to understand php.
Annie
Posts: 20
Joined: Sat May 15, 2010 5:08 pm

Post 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.
Henrie
Posts: 1095
Joined: Sun Aug 14, 2005 8:57 pm

Post 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
I do not monitor the Gbook forums regularly anymore since I do not use the Gbook script myself anymore for a long time. But it helped me a lot in learning to understand php.
Annie
Posts: 20
Joined: Sat May 15, 2010 5:08 pm

Post 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.
Henrie
Posts: 1095
Joined: Sun Aug 14, 2005 8:57 pm

Post 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
I do not monitor the Gbook forums regularly anymore since I do not use the Gbook script myself anymore for a long time. But it helped me a lot in learning to understand php.
Annie
Posts: 20
Joined: Sat May 15, 2010 5:08 pm

Post by Annie »

Many thanks Henrie, it worked a treat.

Annie
cAdams
Posts: 40
Joined: Thu Sep 15, 2011 10:52 pm

Re: Date Format

Post by cAdams »

WAHOO!!! the second option worked for me too :)
To All UALs (Unreliable Arrogant Liars), Go Play On The Motorway
cAdams
Posts: 40
Joined: Thu Sep 15, 2011 10:52 pm

Re: Date Format

Post 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
To All UALs (Unreliable Arrogant Liars), Go Play On The Motorway
Henrie
Posts: 1095
Joined: Sun Aug 14, 2005 8:57 pm

Re: Date Format

Post 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.
I do not monitor the Gbook forums regularly anymore since I do not use the Gbook script myself anymore for a long time. But it helped me a lot in learning to understand php.
Post Reply