Results 1 to 6 of 6

Thread: PHP date() function, what's happening?

  1. #1
    Join Date
    May 2009
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default PHP date() function, what's happening?

    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:



    And here is the PHP:

    PHP Code:
    $datetime=date("l, F I, Y, h:iA"); 
    Can anyone help?
    This is probably a stupid error on my part anyways, haha.
    Last edited by Snookerman; 05-13-2009 at 05:28 AM. Reason: added “Resolved” prefix

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Yes it is a silly error, but that's good because it's nothing big to fix


    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:

    PHP Code:
    $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:

    PHP Code:
    $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.

  3. #3
    Join Date
    May 2009
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Ahh, thank you!
    The day is fixed, but the 2 hour thing is still behind. I suppose I can work that out though, thanks!

  4. #4
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Where do you live?

    Make sure you set the timezone for your server like so:

    PHP Code:
    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...mezone-set.php

    Hope that helps out with the time difference.

  5. The Following User Says Thank You to Schmoopy For This Useful Post:

    xiofire (05-12-2009)

  6. #5
    Join Date
    May 2009
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Hey, thanks! It worked!
    I live in atlantic canada.
    I never heard about the default timezone.
    Thanks!

  7. #6
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    No problem, if you have any more trouble with it I'll be happy to help you.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •