Displaying a null date
Displaying a null date

I am using server-side processing. My SQL database has several date fields. They display correctly when there is a data in the database, but display 1st Jan 1970
when the cell is empty. How do I render these cells so they appear to be empty, please?
This question has an accepted answers - jump to answer
Answers
Is the empty cell and empty string,
null
or something else?Use the browser's network inspector tool to view the JSON response when
1st Jan 1970
is displayed. What is in the JSON response?Kevin
Looks like your database content for your date field isn't ok.
Your database date field should contain NULL for an empty date and not the beginning timestamp of the UNIX epoch.
Here is more on it:
https://stackoverflow.com/questions/8984595/php-date-showing-1970-01-01-after-conversion#:~:text=January%201%2C%201970%20is%20the,a%20(near%2D)%20zero%20result.
You should make sure in your setFormatters that you don't allow this in your data database field.
This is some code from one of my validators that makes sure crap values aren't allowed in the database:
Thanks everyone for your comments. It made me think again and I discovered that the problem was actually of my own making! The database is correct and the columns concerned either have a date (YYYY-MM-DD) or a NULL.
I had previously been using
array( 'db' => 'START', 'dt' => 1,
'formatter' => function($d, $row) {return date( 'jS M Y', strtotime($d));}} ),
in my $columns = (array. I have changed the function to
'function( $d, $row ) {
if ( !$d ) { return ''; }
else
{ return date( 'jS M Y', strtotime($d)); }
and it is working perfectly.