Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8360435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:28:03+00:00 2026-06-09T11:28:03+00:00

In my JavaScript code I have to variables (x and y) with datetime values.

  • 0

In my JavaScript code I have to variables (x and y) with datetime values. All of the following statements return false:

  • x < y -> false
  • x > y -> false
  • x == y -> false
  • x === y -> false

When I debug the code both x and y have the same value ‘Sat Jan 1 12:00:00 UTC+0100 2011’ and the same type.

I am using IE9.

Is there a different way to check if two datetime values are equal?

update (code) – I tried to extract some relevant parts, whole project is very big:

var data;


//Dates are loaded from a webservice and returned as strings; they are parsed with the following function


data = parseD(getDataFromService());

function parseD (data) {
    for (var i = 0; i < data.length; i++) {
        var d = data[i];
        for (var key in d) {
            if (d[key] && d[key].toString().substring(0, 6) === "/Date\(")
                d[key] = new Date(parseInt(d[key].toString().substr(6)));
        }
    }
    return data;
};

function getCssForCell(row, columnID, dataContext, value) {
            var css = "";
            if (columnID === "VF" && value) {
                if (row > 0) {
                    if (data[row].VF < addDays(data[row - 1].VF, 2)) {
                        css = "error_cell";
                    }
                }
            }
            if (columnID === "VU" || columnID === "VF") {
                if (dataContext.VF && dataContext.VU) {
                    if (dataContext.VU <= dataContext.VF) {
                        css = "error_cell";
                    }
                }
            }
            if (columnID === "Rate" && row < (strict_mode ? data.length - 1 : data.length - 2)) { //value for Rate must be assigned
                if (value === undefined || value === null) {
                    css = "error_cell";
                }
            }
            if (columnID === "VF" && row < (strict_mode ? data.length - 1 : data.length - 2)) {
                if (value === undefined || value === null) {
                    css = "error_cell";
                }
            }

            if (columnID === "Rate" && value < 0) {
                css = "error_cell";
            }

            //PROBLEM IN NEXT LINE
            if (columnID === "VU" && row < data.length - 1 && dataContext.VU && data[row + 1] && addDays(dataContext.VU, 1) != data[row + 1].VF ) {
                css = "error_cell";
            }

            return css;
        }

function addDays(date, days) {
    if (date) {
        var result = new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours());
        result.setDate(result.getDate() + days);
        return result;
    }
    return date;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:28:04+00:00Added an answer on June 9, 2026 at 11:28 am

    You should not compare Date object instances, but their values, compare using .getTime() method instead:

    x.getTime() < y.getTime();
    x.getTime() > y.getTime();
    x.getTime() == y.getTime();
    x.getTime() === y.getTime();
    

    .getTime() returns the numeric value corresponding to the time for the specified date according to universal time, this value is the number of milliseconds since 1 January 1970 00:00:00 UTC, also it is equivalent to .valueOf() method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have already checked stackoverflow. Their Jquery/Javascript code is cryptic. The variables are all
I have JavaScript code which copies the value of input file and paste it
Hi I have following JavaScript code that I am trying to run. My aim
have the following javascript code // note: declaring i in this loop for( var
I have some working Javascript code that generates an RDF/XML document using variables picked
please have a look at the following code: (I removed all doctypes etc for
I have two session variables that I retrieve in a Javascript code. This is
If I have some Javascript code like the following... (function(){ var a = 'valueA';
I have a javascript code that have span tag and inside the span tag
I'm currently refactoring some Javascript code we have and amongst other things I've changed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.