Jump to content

Recommended Posts

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)?

Link to comment
https://forums.phpfreaks.com/topic/181295-how-do-you-deal-with-blank-dates/
Share on other sites

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')";

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

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. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.