How to subtract timestamps?

How to subtract timestamps?

jacob22jacob22 Posts: 2Questions: 1Answers: 0

Hi,

I am looking for solution, how to subtract two timestamps. Before I used DataTables plugin, I have specified this in my sql query, but now I do not know if this is possible to do.

In my db I have two columns with time stamps. TimeA and TimeB I need display in table difference between this two times e.g. 20 minutes.

I tried to use render option

"data":null,
render:function (data, type, row) {
return ''+(row.cs_TimeB+row.TimeA)+'';

but it shows following text: 2016-12-04 15:49:032016-12-04 15:49:03

Is there any other way to achieve my goal? e.g. in sql query?

Thanks in advance for your help!

Answers

  • jacob22jacob22 Posts: 2Questions: 1Answers: 0

    I modified above code to this:

    "data":null,
    render:function (data, type, row) {
    return row.TimeB-row.TimeA;

    but it gives me NaN. It looks like my values in TimeA, TimeB columns are string.
    Is there any way to do this, e.g. get this value from JSON?

  • allanallan Posts: 63,833Questions: 1Answers: 10,518 Site admin

    Moment is an outstanding Javascript library for manipulating date time information.

    Allan

This discussion has been closed.