anthony-needs-you Posted January 2, 2009 Share Posted January 2, 2009 Hi i insert my dates from a calander into my mysql database with this: $expireDate = date("Y-m-d", strtotime($_POST['expireDate'])); The client wants it displayed in the input box before being inserted in uk format d-m-Y. If i do this using the above code the database doesnt understand it. I can display it after inserting it but how do i display it in the uk format before insert? Quote Link to comment https://forums.phpfreaks.com/topic/139204-dates-inserted-into-mysql/ Share on other sites More sharing options...
DarkWater Posted January 2, 2009 Share Posted January 2, 2009 There's a few things that need to all be done for this work optimally. 1) I'd suggest inserting your dates like so: <?php $expireDate = strtotime($_POST['expireDate']); $query = "INSERT INTO some_table (expire) VALUES (FROM_UNIXTIME('$expireDate')"; ?> That way, you will always have it as the correct format inside the databsae. 2) When pulling the data, use the MySQL DATE_FORMAT() function. http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format Once you have all that set up, I'd suggest making a timestamp of the date before displaying it. Then, you can call the date() function when you display it, and use the timestamp in the value attribute of the expireDate field on your form. If you do it this way, strtotime() is not needed on the receiving page. Quote Link to comment https://forums.phpfreaks.com/topic/139204-dates-inserted-into-mysql/#findComment-728092 Share on other sites More sharing options...
anthony-needs-you Posted January 2, 2009 Author Share Posted January 2, 2009 Thanks for the tip i will read up on this Quote Link to comment https://forums.phpfreaks.com/topic/139204-dates-inserted-into-mysql/#findComment-728112 Share on other sites More sharing options...
ohdang888 Posted January 2, 2009 Share Posted January 2, 2009 or use the mysql function NOW() Quote Link to comment https://forums.phpfreaks.com/topic/139204-dates-inserted-into-mysql/#findComment-728125 Share on other sites More sharing options...
DarkWater Posted January 2, 2009 Share Posted January 2, 2009 I have a feeling that expireDate != NOW() because that wouldn't make any sense. "This expires...NOW." Quote Link to comment https://forums.phpfreaks.com/topic/139204-dates-inserted-into-mysql/#findComment-728127 Share on other sites More sharing options...
ohdang888 Posted January 3, 2009 Share Posted January 3, 2009 haha sorry, just saw the $date use, thought i'd pop in a trick.. but apparently it was irrelevant Quote Link to comment https://forums.phpfreaks.com/topic/139204-dates-inserted-into-mysql/#findComment-728478 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.