Re-Convert timestamp DATE back to original format (when editing) PHP MySQL

Posted by Jess on Stack Overflow See other posts from Stack Overflow or by Jess
Published on 2010-03-20T02:01:30Z Indexed on 2010/03/20 2:11 UTC
Read the original article Hit count: 348

Filed under:
|
|
|

Ok so I have managed to get the format of the date presented in HTML (upon display) to how I want (dd/mm/yyy)...However, the user also can change the date via a form.

So this is how it's setup as present. Firstly, the conversion from YYYY-MM-DD to DD/MM/YYYY and then display in HTML:

$timestamp = strtotime($duedate); echo date('d/m/Y', $timestamp);

Now when the user selects to update the due date, the value already stored value is drawn up and presented in my text field (using exactly the same code as above).. All good so far.

But when my user runs the update script (clicks submit), the new due date is not being stored, and in my DB its seen as '0000-00-00'. I know I need to convert it back to the correct format that MySQL wants to have it in, in order for it to be saved, but I'm not sure on how to do this. This is what I have so far in my update script (for the due date):

$duedate = $_POST['duedate'];

$timestamp = strtotime($duedate);
    date('Y/m/d', $timestamp);

$query = "UPDATE films SET filmname= '".$filmname."', duedate= '".$duedate;

Can somebody please point me in the right direction to have the new date, when processed, converted back to the accepted format by MySQL. I appreciate any help given! Thanks.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql