jeff5656 Posted November 12, 2009 Share Posted November 12, 2009 I have a DATE field. When somone fills out a form and leaves this field blank, a blank cannot be accepted by the DATE field type, so it gets stored as 12/31 1969. I have used IF statements to convert it to some date way in the future, but that's awkward because then when I'm displaying the records I need another IF statement to not display that date. How do you guys deal with blank dates (that are then converted to 1969)? Quote Link to comment Share on other sites More sharing options...
Caesar Posted November 12, 2009 Share Posted November 12, 2009 Why not keep ANY data from submitting, unless the user inputs a valid date? Maybe I just need to know a little bit more about what you're trying to do.... Quote Link to comment Share on other sites More sharing options...
jeff5656 Posted November 12, 2009 Author Share Posted November 12, 2009 Because I don't know beforehand whether that field will be left blank, or whether they will put in a date. So when I process the form I have to set that variable: $stopdate = date("Y-m-d", strtotime($_POST['stopdate'])); And then when I get to this, if it was blank, it's stored as 1969. $query = "INSERT INTO meds (med_id, pt_id, med, dose, startdate, active, stopdate) VALUES('','$pt_id', '$med', '$dose', '$startdate','$active','$stopdate')"; Quote Link to comment Share on other sites More sharing options...
chauffeur Posted November 12, 2009 Share Posted November 12, 2009 Use $_getdate and use it to auto-fill the field 'if' left blank (""); Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted November 12, 2009 Share Posted November 12, 2009 what is the date? is it todays date? or date of submission? if so you should get the date yourself, and not worry about the user putting a date. also dates are best submit with drop down menus, and if you really want to enforce that they enter a date, you could just make an if statement that does that, and don't submit to the database if the date is empty Quote Link to comment Share on other sites More sharing options...
jeff5656 Posted November 12, 2009 Author Share Posted November 12, 2009 No no no. If the date is blank it means there is no date at all associated with that record, so I don't WANT to put a date in. If the user left it blank, then there is no due date at all. I want it to remain null. However, what I was wondering, is how do you deal with this scenario, where the date is blank and you want to keep it blank but the field is a DATE so it can't be blank. Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted November 12, 2009 Share Posted November 12, 2009 set them to null in the table (rather than a blank value) consult this page for tips on dealing with null values http://dev.mysql.com/doc/refman/5.0/en/working-with-null.html Quote Link to comment 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.