Trouble with converting datetime from WebApi
Trouble with converting datetime from WebApi
![Mattias83](https://secure.gravatar.com/avatar/2e8087696afcc1816397ef493781fe3f/?default=https%3A%2F%2Fvanillicon.com%2F2e8087696afcc1816397ef493781fe3f_200.png&rating=g&size=120)
Good day all
I have some trouble with getting a correct datetime format from data coming from a WebApi that i want to use in my table.
the data looks like this:
{
"data": [
{
"Pfid": 61000,
"Typ": "D",
"Pplats": "636-05-B",
"Artnr": "VSV182840",
"Artben": "Galler Spirit 800C KPL",
"Saldo": 3,
"Saldotyp": "ST",
"Saldoochtyp": "3 ST",
"Pgrp_nr": 1035,
"Ordernr": "116595",
"Rappnr": 23382114,
"Trp": "646",
"Artrev": "1",
"Pkg": 1,
"Pkg_total": 1,
"Reported_by": "Lillo Italo Valdivia",
"Datum": "2018-12-04T05:48:14.183",
"Npgrp_nr": 0,
"Op": 0,
"Nop": 0,
"Flyttad": "2018-12-04T13:23:33.33"
}
]
}
and this is my datatable config using moment and datetime plug-in
<script src="/DataTables/datatables.min.js"></script>
<script src="/DataTables/datetime/moment.js"></script>
<script src="/DataTables/datetime/datetime.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#example').DataTable({
ajax: {
"url": '/api/MaMaDB/GetPfInfo?user=test',
"type": "GET"
},
columns: [
{ data: "artnr" },
{ data: "artben" },
{ data: "saldo" },
{ data: "saldotyp" },
{ data: "pgrp_nr" },
{ data: "ordernr" },
{ data: "rappnr" },
{ data: "trp" },
{ data: "reported_by" },
{ data: "datum" },
],
columnDefs: [
{ targets: 9, render: $.fn.dataTable.render.moment('YYYY-MM-DD') }
]
});
});
</script>
but i only get invalid date in the date column and not the date format that i want
if i dont use datetime plugin datatables will just output the date as 2018-12-04T05:48:14.183
Any idea how i need to modify the settings for it to recognize the dates in the data correctly?
Best Regards
Mattias
Replies
Hi @Mattias83 ,
You need to manipulate that date, as the format needs converting. See here, this is using one of your date formats,
Cheers,
Colin
that worked perfectly, many thanks![:) :)](https://datatables.net/forums/resources/emoji/smile.png)