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 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2013
    Location
    Finland/Estonia
    Posts
    53
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Changing the format of Date fails, comes out as Epoch

    Hi. I need to convert a d/m/Y (ex. 01/01/2014) into a F j, Y format, (January 1, 2014). Basically what I'm doing is POSTING the d/m/Y format date , binding it to the variable $postDate;


    PHP Code:
    $postDate $_POST['datepicker'];
    echo 
    "Posted Date: $postDate <br>"//Shows up just fine
    $old_date date('d/m/Y'$postDate);
    echo 
    "Old Date: $old_date<br>"//Epoch
    $old_date_timestamp strtotime($old_date);
    $newDate date('F j, Y'$old_date_timestamp); // Epoch 
    What am I doing wrong?
    Last edited by estXcrew; 01-17-2014 at 06:33 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    There is no format that accepts d/m/y in PHP. If you have it available, you can use createfromformat method on the DateTime object to parse it. 1/1/2014 itself is valid though, but only because its m/d/y matches the d/m/y.

    That said, you cannot use date() on a string, it has to be an integer. $postDate as you describe is an input on the 1/1/2014 and must first be converted to a validate integer or datetime datatype. Offhand I don't know if there's a procedural method, but you can always split it up manually with explode and use create_date instead. Using the datetime::createFromFormat is probably easier to do though.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Tags for this Thread

    Posting Permissions

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