Page 1 of 1

Insert Null date in database

Posted: Fri Apr 07, 2017 6:29 am
by DEEPAKD
Hi All


I have two questions.
1) How to insert null date in database.if the date is empty.
2) and how to insert date plus time from grid ( table ) into database.



Thanks in advance

Re: Insert Null date in database

Posted: Fri Apr 07, 2017 7:43 am
by mishika
Hello,

1. To enter a NULL value for date:
If you are using a PM Table, you need to tick the NULL column of the date field of your table. This will allow the field to store the NULL value.
In a trigger, check the value of variable x and fire the query accordingly. If you pass a value for the date, it will be set to that value. You can refer the following query:
Code: Select all
INSERT INTO PMT_MY_TABLE (NAME, PLACE, DATE) VALUES ('$name', '$place', '$date');
To set the value of the date as NULL, you can refer the following SQL query:
Code: Select all
INSERT INTO PMT_MY_TABLE (NAME, PLACE) VALUES ('$name', '$place');
2. To enter date plus time in database:
Take the DateTime field(say date1) in the grid(say gridVar001) and set its format to : YYYY-MM-DD, h:mm:ss
In the database take the DATE field of type DateTime.
And create a trigger which gets the value the date1 field of the grid and stores in the database.
An example of trigger can be as follow:
Code: Select all
@@d = @@gridVar001[1]['date1'];
$date1 = @@d;
$query = "INSERT INTO PMT_MY_TABLE (NAME, PLACE, DATE) VALUES  ('name', 'place', '$date1')";
@@res = executeQuery($query);
Hope this helps

Best Regards
Mishika