Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Basic PHP and Objects

    Hi,

    I consider myself a decent programmer. However, I often run into some problems when I try to learn new things. Right now, I am simply trying to take a date and output in GMT format. To do this, I was at php.net and found the example shown below. However, neither the object style nor the procedural style work for me.

    Why is it that my server produces and error for each method?

    $date = DateTime::createFromFormat('j-M-Y', '15-Feb-2009');
    echo $date->format('Y-m-d');

    $date = date_create_from_format('j-M-Y', '15-Feb-2009');
    echo date_format($date, 'Y-m-d');


    Thanks

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Make sure your error reporting is enabled:
    PHP Code:
    ini_set('display_errors'1);
    error_reporting(E_ALL); 
    Or check the error logs; does it show any error on that call to createFromFormat?

  • #3
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks

    It tells me that the method DateTime::createFromFormat() is undefined

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Then your PHP version is too old to use DateTime::createFromFormat.
    The format you have here though passes gnu specifications for datetime string formats. You can simply replace the line for create from format with $date = new DateTime('15-Feb-2009');


  •  

    Posting Permissions

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