dmccabe Posted December 31, 2008 Share Posted December 31, 2008 After Mchl helped me out with my date formatting, everything was fine. However I have now carried on working on my app and come back to find now that date isnt working again and I cannot work out why. When the date is enterred and the update query is run, it doesnt actually update the database, but also chucks no errors. First I have the user input where they put the date in like 01/12/08: <td>Date In: (DD/MM/YY)</td> <?php if ($row['DATE_IN'] != "0000-00-00") { $datein = date("d/m/y",strtotime($row['DATE_IN'])); } ?> <td><input type="text" name="DATE_IN" value="<?php echo $datein; ?>"></td> then when the user clicks submit it should update the database field which is a "date" format. echo "Date In: " . $_POST['DATE_IN'] . "<br />"; $date_in = date("d-m-Y",strtotime(str_replace("/","-","{$_POST['DATE_IN']}"))); echo "Date In: " . $date_in . "<br />"; I put the echo's round it to check what was happening and if the value was being passed from the form. Then the database update: $update = "UPDATE `tbl_vehicles` SET `REG` = '$reg', `MAKE_ID` = '$make_id', `MODEL_ID` = '$model_id', `COLOUR_ID` = '$colour_id', `FUELTYPE_ID` = '$fueltype_id', `TRANSMISSIONTYPE_ID` = '$transmissiontype_id', `MILEAGE` = '$mileage', `LOCATION_ID` = '$location_id', `OFF_FLEET_DATE` = '$off_fleet_date', `EST_PRICE` = '$est_price', `STATUS_ID` = '$status_id', `ACC_STATUS_ID` = '$acc_status_id', `ORIGIN` = '$origin', `DATE_IN` = '$date_in', `EST_REFURB` = '$est_refurb', `ACTUAL_REFURB` = '$actual_refurb', `PO_NO` = '$po_no', `DATE_READY` = '$date_ready', `TOTAL_HOURS` = '$total_hours', `BOOKPACK` = '$bookpack', `VALET` = '$valet' WHERE `ID` = '$id'"; if (!mysql_query($update)) { die(mysql_error()); } else { echo "Vehicle updated! <br />"; } Now everything else in this update command is working fine and all other values are being updated, but in the database the date in and other dates stay as "0000-00-00" please help I just cant find whats wrong. Link to comment https://forums.phpfreaks.com/topic/138978-solved-still-having-problems-with-dates/ Share on other sites More sharing options...
xtopolis Posted December 31, 2008 Share Posted December 31, 2008 If the date entered is Dec 31st, 2008 (in day - month - year) => 31/12/2008 and you format it like that: date("d-m-Y"); == day - month - year... 31-12-2008 how will it ever match the database column's expected Y-m-d format? 0000-00-00 Link to comment https://forums.phpfreaks.com/topic/138978-solved-still-having-problems-with-dates/#findComment-726834 Share on other sites More sharing options...
dmccabe Posted December 31, 2008 Author Share Posted December 31, 2008 But thats the odd bit, it was working :/ so if the user is inputting as dd/mm/yy How do I switch it to YYYY-mm-dd as the database wants Link to comment https://forums.phpfreaks.com/topic/138978-solved-still-having-problems-with-dates/#findComment-726836 Share on other sites More sharing options...
Mchl Posted December 31, 2008 Share Posted December 31, 2008 Did I show you "d-m-Y"? My mistake then... it's the format I always use in my apps for displaying dates. For storing in MySQL it's always year,month,day,hour,minute,second order ("Y-m-d" for example). Please see below, for some source reference material http://dev.mysql.com/doc/refman/5.1/en/date-and-time-types.html Link to comment https://forums.phpfreaks.com/topic/138978-solved-still-having-problems-with-dates/#findComment-726839 Share on other sites More sharing options...
xtopolis Posted December 31, 2008 Share Posted December 31, 2008 On top of that, I found an example http://us2.php.net/manual/en/function.strtotime.php#85969 in the manual showing how to convert a date from one thing to another. Summary: (you just have to lookup the order of mktime's parameters <?php $r = "29/9/2008"; $date = explode("/",$r); echo date("D d M",mktime(0,0,0,$date[1],$date[0],$date[2]))."\n"; ?> Link to comment https://forums.phpfreaks.com/topic/138978-solved-still-having-problems-with-dates/#findComment-726840 Share on other sites More sharing options...
dmccabe Posted December 31, 2008 Author Share Posted December 31, 2008 thats the one, Mchl there is a good chance you told me right, but I may have screwed the code up again at some point Link to comment https://forums.phpfreaks.com/topic/138978-solved-still-having-problems-with-dates/#findComment-726857 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.