![]() |
My date when leave blank still save this format in my db:1970-01-01 - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: My date when leave blank still save this format in my db:1970-01-01 (/showthread.php?tid=42794) |
My date when leave blank still save this format in my db:1970-01-01 - El Forum - 06-19-2011 [eluser]Wondering Coder[/eluser] first of all, morning and hi to all CI fans. Code: $save_project = $this->input->post('save_project'); I have this code above that save the data's in my db. As you can see I have 5 dates, and a user can choose to select a date or not. Now my problem is when the user submit/save the data's and the date's leave as blank in my db it still save this format date: 1970-01-01 I have this date type in my db: Code: CREATE TABLE IF NOT EXISTS `spms_project` ( and also I'm using a js calendar library, don't know if my calendar lib is causing this but I've looked in it,doesn't have a default date that will save 1970-01-01. My date when leave blank still save this format in my db:1970-01-01 - El Forum - 06-19-2011 [eluser]R_Nelson[/eluser] so is it saving it as 1970-01-01 or is it saving it 0000-00-00? My date when leave blank still save this format in my db:1970-01-01 - El Forum - 06-19-2011 [eluser]Wondering Coder[/eluser] its saving 1970-01-01 when the text field for calendar is blank or the user didn't choose a date. My date when leave blank still save this format in my db:1970-01-01 - El Forum - 06-19-2011 [eluser]jmadsen[/eluser] @wondering Coder, if you use the date formatting on a null value, it will default to 1970-01-01. Ex. Code: echo date('Y-m-d',strtotime(null)); You need to exclude those lines if your user doesn't submit a date My date when leave blank still save this format in my db:1970-01-01 - El Forum - 06-20-2011 [eluser]Wondering Coder[/eluser] how am I supposed to do that? Since I have 4 dates I don't want to use if-else condition since it will give pressure on my db. Also tried using empty and isset function but still the same, when the value is null it save 1970-01-01. Also I cannot used CI validation for the reason that a user can and cannot choose to input dates. My date when leave blank still save this format in my db:1970-01-01 - El Forum - 06-20-2011 [eluser]jmadsen[/eluser] what do you mean, "pressure on your db"? you have four elements in your array, this one for example: 'photos_date' => date('Y-m-d',strtotime($this->input->post('photos_date'))) take it out of the array you have now, and only add it conditionally. something like: Code: if ($this->input->post('photos_date')){ Put that AFTER your current array setup. if $project_info['photos_date'] isn't there, it won't get passed in the INSERT statement, and the default will be used My date when leave blank still save this format in my db:1970-01-01 - El Forum - 06-20-2011 [eluser]Wondering Coder[/eluser] hi jmadsen, used if-else condition and figured out how not to mess up the code but I have slight problem could you take a look at my link/new thread: http://ellislab.com/forums/viewthread/192014/ |