jeff5656 Posted January 21, 2009 Share Posted January 21, 2009 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 More sharing options...
Mchl Posted January 21, 2009 Share Posted January 21, 2009 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) Link to comment https://forums.phpfreaks.com/topic/141818-date-field-has-1969-12-31/#findComment-742488 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.