Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
01-17-2014, 06:27 PM #1
- Join Date
- Jul 2013
- 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;
$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
Last edited by estXcrew; 01-17-2014 at 06:33 PM.
01-17-2014, 06:59 PM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- 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.
header('HTTP/1.1 420 Enhance Your Calm');