SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ghost time appears when converting date format

    Hi all,

    Here's something you probably don't see everyday.

    So we have a datetime $content[$i] in the format of "Saturday 13th of February 2010"

    I'm adding on a "12:00pm" just so it gets a time too (not simply a date).

    I then go and convert it into DATE_RFC822 for a RSS feed.

    As soon as I do that and print it to the screen to check it magically inserts the current date into the string. In other words you'll get the below:

    Sat, 13 Feb 10 15:46:09 +0000

    Surely there should be a) no time in there or b) 12:00pm in there if I append the 12:00pm to it before processing? Maybe I need to be forcing the 12:00pm part in there via another perhaps more datetime orientated method for it to play ball with me?

    $content[$i] = $content[$i] ." 12:00pm";

    $convert_date_obj = new DateTime(strtotime($content[$i]));
    $convert_date_obj->setTimezone(new DateTimeZone('GMT'));
    print "Result: " .$convert_date_obj->format(DATE_RFC822);

    Thanks,

  2. #2
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry guys.

    It would seem I've solved it via:

    $convert_date_obj->setTime(12, 00, 00);

    Surprisingly the modify method wouldn't work though. Very picky.

  3. #3
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    strtotime on "Saturday 13th of February 2010" fails, your time jiggery-pokery doesn't factor in.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


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
  •