View Full Version : Resolved PHP date() function, what's happening?
xiofire
05-12-2009, 08:57 PM
I was happily scripting my blog for the Portfolio I'm building, then along comes the date() function.
Well, the problem is, I posted the comment (originally) on May 12, 5:15.
The output says I posted the comment 11 days and 2 hours back.
I am having this problem with the comments and the blog entries themselves.
Screenshot:
http://dev.limecore.net/photo/uploads/date()bug.png
And here is the PHP:
$datetime=date("l, F I, Y, h:iA");
Can anyone help?
This is probably a stupid error on my part anyways, haha.
Schmoopy
05-12-2009, 09:06 PM
Yes it is a silly error, but that's good because it's nothing big to fix :D
From php.net:
I (capital i) Whether or not the date is in daylight saving time 1 if Daylight Saving Time, 0 otherwise.
You've got:
$datetime=date("l, F I, Y, h:iA");
Notice the I.
So you're in DST and it's a boolean value, so it shows a 1.
This is not the first of May...
What you want is:
$datetime=date("l, F j, Y, h:iA");
Hope this solves your problem.
j shows the actual day, without leading zeros.
You can use "d" if you want to have them.
xiofire
05-12-2009, 09:55 PM
Ahh, thank you!
The day is fixed, but the 2 hour thing is still behind. I suppose I can work that out though, thanks!
Schmoopy
05-12-2009, 09:59 PM
Where do you live?
Make sure you set the timezone for your server like so:
date_default_timezone_set('Europe/London');
I live in Europe so I set mine like that.
For other timezones look at this page: http://uk.php.net/manual/en/function.date-default-timezone-set.php
Hope that helps out with the time difference.
xiofire
05-12-2009, 10:09 PM
Hey, thanks! It worked!
I live in atlantic canada.
I never heard about the default timezone.
Thanks!
Schmoopy
05-12-2009, 10:15 PM
No problem, if you have any more trouble with it I'll be happy to help you.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.