what is preventing dates from being identical in apps script?

Link to public spreadsheet: https://docs.google.com/spreadsheets/d/1pXrUkA-fY1hw3bie4Bv1mamkmzics9dfX59B12spuPI/edit?usp=sharing

Issue: Encountering discrepancies between seemingly identical dates in Google Apps Script. There is a sheet containing dates, and the script checks if one date matches the previous date. Expected output (starting from the second row) should be true, false, true. However, actual output is false, false, false. Any insights on why this discrepancy occurs?

9/8/2020
9/8/2020 // expected true, but returns false
9/15/2020 // expected false, correct
9/15/2020 // expected true, but returns false

Snippet of the code:

// Test code
for (var r = 10; r <= 14; r++){
for (var c = 2;c <= 4; c++){
    Logger.log(sh.getRange(r,c).getValue());
    Logger.log(sh.getRange(r-1,c).getValue());
    Logger.log(sh.getRange(r,c).getValue() == sh.getRange(r-1,c).getValue());
}}

Logger response (showing that dates are objects, but equivalent dates aren't...):
[20-10-25 17:05:30:975 EDT] Tue Sep 08 00:00:00 GMT-04:00 2020
[20-10-25 17:05:30:976 EDT] object
[20-10-25 17:05:30:977 EDT] Tue Sep 15 00:00:00 GMT-04:00 2020
[20-10-25 17:05:30:979 EDT] object
[20-10-25 17:05:30:980 EDT] false
[20-10-25 17:05:30:981 EDT] false
[20-10-25 17:05:30:982 EDT] Tue Sep 15 00:00:00 GMT-04:00 2020
[20-10-25 17:05:30:984 EDT] object
[20-10-25 17:05:30:986 EDT] Tue Sep 15 00:00:00 GMT-04:00 2020
[20-10-25 17:05:30:987 EDT] object
[20-10-25 17:05:30:989 EDT] false
[20-10-25 17:05:30:990 EDT] false

Answer №1

@Lucas found a helpful solution regarding date manipulation. When comparing dates, it's important to consider the entire object rather than just the values. To ensure accurate results, extracting the isostring for comparison is proving effective:

array[0][1].toISOString()

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ensure that the jQuery Ajax each function verifies if the returned ID matches the one preceding it

Using AJAX, I am fetching data from a remote server and then using a loop to iterate through it. My goal is to perform an action only once if the returned value data matches the previous one. For example, if there are 10 instances of val.userId == 1, I wa ...

Troubleshooting a Dysfunctioning Character Counter Feature in a JavaScript Input Field

I've been working on a fun little project to practice my JavaScript skills - a plate calculator. Here's the gist: you enter your name, and each letter costs $5, so the total cost of the plate is the length of your name multiplied by $5 (this pro ...

Refusing to invoke a Python function from JavaScript with the likes of an e

I'm having an issue with a toggle feature in my Eel application. Unfortunately, when I try to print "Test" to the terminal, it doesn't seem to work as expected. <div class="container-afk"> <label class="toggle_box" ...

JavaScript code not running with Node.js module

Currently, I am utilizing node.js to operate an HTTP server locally. Whenever a request is made from the server, the response is delivered through res.end(data). In this scenario, the variable data contains JavaScript code. document.body.innerHTML="<if ...

Header input for searching in a different section of the page

I am working on a project where I have a Header component containing an Input element. My goal is to search within an array located in another component, specifically the product list component. Both of these components are connected through App.js. How ...

Centering an image that is absolutely positioned within a container that is relatively positioned, horizontally

Looking to center an image that is positioned absolutely horizontally within a container that is relatively positioned. After attempting with CSS and not finding success, I ended up using Jquery. http://jsfiddle.net/CY6TP/ [This is my attempt using Jquery ...

MongoDB error codes and their associated HTTP status codes are important for developers to understand

When a new user attempts to sign up with an existing user account, MongoDb triggers a 11000 error code In Express, handling this scenario can be done as follows: async function signup(req, res, next){ try{ // perform some actions }catch(err){ i ...

Having trouble getting the auto complete feature to work in AngularJS with jQuery

I have been attempting for the last 5 hours without any success... Below is the code snippet: Within View: <input type="text" ng-model="foo" auto-complete/>Foo = {{foo}} Inside the controller: myapp.directive('autoComplete', functi ...

fetch a particular value using jQuery and display it

Seeking assistance here! I am in the process of consuming a Web Api service from an MVC ASP.NET App using jQuery's function $.ajax. The goal is to retrieve a specific record from the database. While I can successfully connect to the service and fetch ...

Versatile accordion with separate functionalities for items and panels

When I have different functions for clicking on item and title, clicking on the item works fine but clicking on the panel triggers both functions. Is there a way to resolve this so that I can click on the item using Function_1 and click on the panel using ...

Issue with React and Material UI: The Textfield's "onChange" event is not being triggered

I have been attempting to trigger an onchange function when my Textfield is populated, but for some reason the function never seems to be activated. Despite seeing changes triggered by the React devtool plugin in Chrome, I am at a loss. Any suggestions? i ...

Transforming c# data sourced from entity framework into a proper JSON format

Below is a method I have: [HttpPost] public ActionResult GetData() { var data= (dynamic)null; using (DBContext context = new DBContext()) { data= context.MyObject.Where(i=> i.TypeId == 1).OrderBy(k => ...

Retrieving FormData using ajax and passing it to aspx.cs code

After adding a debugger in the console, I am receiving confirmation that the file has been uploaded successfully. However, the debugger is not reaching the code behind, or in other words, the code behind is not accessible. This is the JavaScript file: fun ...

Making a HTTP GET call in NodeJS using the http.get() method to an external API

I'm encountering an issue with my NodeJS (using Express) HTTP GET request to an external API. Despite properly setting up my code, I'm not receiving any data in return. Here is the snippet: import * as http from "http"; const options = { h ...

Can JavaScript/jQuery be integrated with MySQL/PHP?

I have a unique question that I've been unable to find an answer to, which may indicate its complexity. The reason for my inquiry is because I am in the process of developing a food delivery website. Within the admin panel of this website, administrat ...

Showing a temporary marker while utilizing jQuery UI sortable container

Incorporating a sortable list of items using jQuery UI in a bootstrap layout has been successfully declared. $("#ReportContainer").sortable({ helper: 'clone', revert: 'invalid', }); Each draggable item represents a column size ra ...

Strain out specific keys from an array of objects

After utilizing the API, I receive an array of objects structured as follows: [ { id: 5, name: "foo" }, { id: 7, name: "bar" } ] My goal is to extract only the ID values and transform the array into this format: [5,7] What approach would be regarded ...

Navigate to the following div, navigate back to the previous div

I am attempting to implement a div navigation system with next/previous buttons. Despite searching extensively on Google, I have not found the exact solution I am looking for. First and foremost, I want to maintain the integrity of my html structure. < ...

What is causing the Denial of Service in react-svg-loader version 3.03 - Could it be related to css-what

An issue has been identified with React solution, showing a high vulnerability in npm-audit. The vulnerability is related to Denial of Service in react-svg-loader version 3.03 due to css-what. What potential solutions exist for this issue? Specific detai ...

Is your href in javascript not functioning properly?

Recently, I completed the development of a mobile web application. Overall, everything seems to be working smoothly except for one issue: there is a link with JavaScript in its href that is causing problems. Strangely enough, this link works perfectly fi ...