check if date is older then today
check if date is older then today
I have another Question, so i opend a new one
I have to change the color of an enty if the date is older then the current date
i would like to do it with those lines but need to know how to get the current date
/**
* name column 2
*/
"columnDefs": [
{ className: "payed_untill", "targets": [ 1 ] }
],
/**
* color not payed red
*/
"fnRowCallback":function(nRow, aData ) {
if (aData[1] < -->current date somehow<-- ) {
jQuery('td.payed_untill', nRow).css('color', 'red');
}
},
Thank you in advance
This question has an accepted answers - jump to answer
Answers
Are you using Moment.js?
Agreed - Moment is what I always reach for when doing date / time calculations in Javascript. It can be overkill sometimes, for example if your
aData[1]
was ISO8601, then it would be easy to useDate.parse()
to get it andnew Date()
to get the current day and subtract one for the comparison.Allan
did not know about it, thank you, it works now
hmm or maybe not.
it colors only one field
honestly, i suck at this
What is
aData[1]
? i.e. what is the data in it? If it is a string, you'll need to convert it to be a date, as I mentioned above.Allan
Sorry for the late answer.
aData[1] is the "payed untill" filed you can see in the picture below.
So what i need is, that the date turns red if the actual date is past the date in the filed.
Ok, so this is actually working.
The problem was really dumb.
I am writing on a german PC in Spain so the spanish date is written DD/MM/YYYY and german its DD.MM.YYYY.
Just had to sort that out and now it works almost fine.
its seems to work better by setting .format to:
.format('YYYY/MM/DD')
Thanks for posting back. Good to hear you have it working now.
Allan