2

I have a simply compare in my *.s file:

        var lastSelectedDate = new Date(DateConvert(value));
        var todayDate = new Date($.now());            

        if (lastSelectedDate < todayDate) {
            return false;
        }
        else {
            return true;
        }

When I reach if, I have second values:

lastSelectedDate = Thu Apr 23 2015 00:00:00 GMT+300
todayDate = Thu Apr 23 2015 15:18:31 GMT+300

It is obvious that lastSelectedDate < todayDate

BUT, the thing is, I need to compare those dates without time (condition is for lastSelectedDate to be greater or equal).

Ofcourse It can be done by using .getDay() .getMonth() .getYear() but is there another way to exclude time from it? Without additional libraries?

Olegs Jasjko
  • 2,128
  • 6
  • 27
  • 47
  • Short answer, no not really. You would need to use `setHour`, `setMinute` etc to force the `todayDate` to `00:00:00` – Rory McCrossan Apr 23 '15 at 12:39
  • Something like [this question](http://stackoverflow.com/questions/2698725/comparing-date-part-only-without-comparing-time-in-javascript). – Regent Apr 23 '15 at 12:43
  • I thinked about it but there no way to... make in at once? Potentially I will have another similar comparison and that mean, I need to create a function for droping time (DateConvert for example, swap day and month)... – Olegs Jasjko Apr 23 '15 at 12:45
  • @OlegsJasjko then it is time to write this function. – Regent Apr 23 '15 at 12:53

2 Answers2

2

Just add "setHours" to your code:

var todayDate = new Date().setHours(0,0,0,0)
freethinker
  • 2,257
  • 4
  • 26
  • 49
0

You could use Date.prototype.setHours() to set hours, minutes, seconds and milliseconds all to 0.

 if (lastSelectedDate.setHours(0,0,0,0) < todayDate.setHours(0,0,0,0)) {
xdazz
  • 158,678
  • 38
  • 247
  • 274