Avatar ·

How to compare two dates in JavaScript? Finding difference and checking equality

Hello everyone! I'm a beginner in JavaScript and can't figure out date comparison. I have two dates: one comes from the server as a string "2025-03-15T10:30:00Z", and the second I create via new Date() for the current moment. I need to understand which date is earlier, and check if they are equal to the day precision (without time).\n\nI tried simply writing date1 > date2, but it doesn't work — I get strange results. When I output both dates to the console, they look something like this: "Sat Mar 15 2025 13:30:00 GMT+0300" and "2025-03-15T10:30:00.000Z". Apparently, the problem is in the format?\n\nHere is my code that doesn't work:\n\n```javascript\nlet dateFromServer = "2025-03-15T10:30:00Z";\nlet currentDate = new Date();\n\nif (dateFromServer > currentDate) {\n console.log("Date from server is greater");\n} else {\n consol