Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

datetime NULL

Questions related to using nuBuilder Forte.
Locked
marc
Posts: 92
Joined: Mon May 14, 2018 3:26 pm

datetime NULL

Unread post by marc »

I have a nuDate input field which data type is datetime, with a default value of NULL.
It saves correctly when a date value is entered; however when the date is cleared out the value is stored as 0000-00-00 00:00:00 instead of NULL.
It needs to be stored as NULL. How can I fix it?
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: datetime NULL

Unread post by toms »

Hi,

Add this in the After Save Event (PHP):

Code: Select all

if ('#your_date_field#' == "") {
    $sql = "UPDATE table_name SET your_date_field = NULL WHERE table_name_id = '#RECORD_ID#' ";
    nuRunQuery($sql);
}
Replace:

table_name: name of your table
your_date_field: field to be updated
table_name_id: primary key of your table
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: datetime NULL

Unread post by admin »

.
marc
Posts: 92
Joined: Mon May 14, 2018 3:26 pm

Re: datetime NULL

Unread post by marc »

toms, thanks!
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: datetime NULL

Unread post by admin »

.
Locked