Jump to content

DATE field has 1969-12-31


jeff5656

Recommended Posts

I have a DATE field, but if it is blank, the date is stored as: 1969-12-31

 

How do I modify this code to make that date blank unless a user types in a date?

 

$cxr_date = date("Y-m-d", strtotime($_POST['cxr_date']));  

INSERT INTO sarcoid (cxr_date, etc) VALUES ($cxr_date, $etc)

 

Do I have to change that field to NULL instead of NOT NULL??

Link to comment
https://forums.phpfreaks.com/topic/141818-date-field-has-1969-12-31/
Share on other sites

 

Do I have to change that field to NULL instead of NOT NULL??

 

Yes you do. And when there is no date insert NULL into it.

[edit] actually... empty string will be enough

 

if(!empty($_POST['cxr_date'])) {
  $cxr_date = "'".date("Y-m-d", strtotime($_POST['cxr_date']))."'";
} else {
  $cxr_date = "";
}

INSERT INTO sarcoid (cxr_date, etc) VALUES ($cxr_date, $etc)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.