arcdragon Posted December 5, 2009 Share Posted December 5, 2009 I am trying to take a user entered month, day, and year from an HTML/PHP form and store it in a mySQL database.. Code: $exp_date = date('n/d/Y', strtotime($_POST['exp_month'] . '/' . $_POST['exp_day'] . '/' . $_POST['exp_year'])); Expected result for $exp_date: MM/DD/YYYY But instead I'm getting: 0.000004, which seems to be the result of dividing the variables together. And completely incapable of being stored in a DATE formatted field. Please help. I'm starting to claw at my eyes. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/184067-need-to-store-user-entered-dates/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 5, 2009 Share Posted December 5, 2009 A mysql DATE data type has a format YYYY-MM-DD, not MM/DD/YYYY. DATE values are strings and must be encompassed in single-quotes in the query. When they are not enclosed in single-quotes, they are a math expression (the correct YYYY-MM-DD format is a subtraction math expression and the format you are attempting is a division math expression.) Quote Link to comment https://forums.phpfreaks.com/topic/184067-need-to-store-user-entered-dates/#findComment-971791 Share on other sites More sharing options...
cags Posted December 5, 2009 Share Posted December 5, 2009 Plus 'n' is month without leading zero which won't always give you MM. Quote Link to comment https://forums.phpfreaks.com/topic/184067-need-to-store-user-entered-dates/#findComment-971794 Share on other sites More sharing options...
arcdragon Posted December 5, 2009 Author Share Posted December 5, 2009 This is very helpful. Any chance I could get a bit of sample code that goes with it? Quote Link to comment https://forums.phpfreaks.com/topic/184067-need-to-store-user-entered-dates/#findComment-972064 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.