Donjwan Donjwan - 4 months ago 55
jQuery Question

Datatable > highlight date

I am using datatable framework an I want to highlight date which has been passed away

for example now it is 12:00 AM if there is any row how have date and time before 12:00 AM today it should be red

This is the code that I am trying to edit

"createdRow": function ( row, data, index ) {
if ( data[10].replace(/[\$,]/g, '') * 1 < 150000 ) {
$('td', row).eq(10).addClass('highlight');
} ,

basically my idea is to make this code look like this

if ( data[10].replace(/[\$,]/g, '') < now) {

my time format is like this

2016-09-01 05:09:07

any ideas ?

var dt = '2016-09-01 05:09:07'.replace(/\s/, 'T') + 'Z';
console.log((new Date(dt)) > (new Date()));

For more information you can see here: Converting string to date in js

If you want highlight datetime ranges you can increase/decrease Date object state.