Problem in formatting date time in momentjs
Problem in formatting date time in momentjs

I'm making date time difference between a date time from database and current time but it return string like:
PT6H8M38S
-PT42M57S
my code:
ar tdy= new Date();
var dt= tdy.getFullYear()+'-'+(tdy.getMonth()+1)+'-'+tdy.getDate();
var time= tdy.getHours() + ":" + tdy.getMinutes() + ":" + tdy.getSeconds();
var dateTimeJs= dt+' '+time;
var dateDTD= 2020-01-02 08:38:52
moment.duration(moment(dateTimeJs).diff(moment(dateDTD)))
I know this is not for moment js but i want to know is there a feature in datatable ?
This discussion has been closed.
Replies
I'm not clear what the issue is, but would use
columns.render
to modify the cell data to look how you want it.Colin
The issue is i want to make date time difference between stored datetime in database and time now, so when i do i get string PT6H8M38S
PT means Pakistan Time here but i want it to be more human friendly and readable, i try to format
moment.duration(moment(dateTimeJs).diff(moment(dateDTD))).format('YYYY-MM-DD HH:MM:SS');
but it return invalid date
Maybe you can provide a simple test case that we can look at and help you build the proper moment statement. Moment.js might not be interpreting the datetime correctly with
moment(dateTimeJs)
ormoment(dateDTD)
. You may need to include the source datetime format as described here:https://momentjs.com/docs/#/parsing/string-format/
Kevin
This doesn't sound like a problem specific to DataTables, more like a Moment/Javascript issue - it would be worth asking on StackOverflow for advice there.
Colin
Thanks for your suggestions, i'll look into it.