Invalid date with datetime-moment.js
Invalid date with datetime-moment.js
Rappi
Posts: 82Questions: 18Answers: 1
Hi.
I have a databasefield with "YYYY-MM-DD" format.
In my js I have this:
$(document).ready(function() {
$.fn.dataTable.moment( 'DD.MM.YYYY' );
and in the data this:
data: "tm_mm_mitglieder.Geburtsdatum",
render: function ( data, type, row ) {
return (moment(data).format("DD.MM.YYYY"));
}
All is working but when the date in the database is empty or "0000-00-00" the table show "Invalid date" and the sorting is not working.
Then I have played with this:
data: "tm_mm_mitglieder.Geburtsdatum",
render: function ( data, type, row ) {
var rowvalueallday = row["5"];
if (rowvalueallday == '0000-00-00') {
var gdat = '1900-01-01';
return gdat;
} else {
return (moment(data).format("DD.MM.YYYY"));
}
But it's not working.
How can I make the sort working correct and show "00.00.0000" or "Kein Datum angegeben" in the table?
Rappi
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Hi Rappi,
I was going to suggest basically what you have done - to an
if
condition to see if the date is valid or not. If that isn't working, I would need a link to a page showing that issue so I can debug it.Thanks,
Allan
Hi Allan.
It's not an open system.
You can insert this URL
http://www.rappi.de/Tier-Management/modules/Mitglieds-Management/mitglieder.php
login with demo/demo and insert the URL again.
Than you See the Problem in the col "Geburtsdatum".
Rappi
The error is
var rowvalueallday = row["5"];
. Just use thedata
parameter passed in since that already points to thetm_mm_mitglieder.Geburtsdatum
data!The issue with
row['5']
is that there is no5
data property in your data source object.Allan
Thanks for your answer.
Now I have
Same error :-(
I think, the moment convert the data before gdat returns and have a problem with a date like 0000-00-00.
Another idea?
Rappi
I have played with but no solution found :-(
Now I don't have an idea.....
That is not correct. It is a Javascript object, so you would use:
or just use the
data
parameter as I suggested above.Allan
You are my hero (again) :-D
Thanks!
PHP is my world but JS ...... Umpff
Rappi
I had followed by your solution it working to render date time.
but it's not working to sorting date.
What should I do? or Mr.Rappi Could you please help me?
Watchara.
@Watchara - Please link to a test case showing the issue.