# Comparing objects with dates in JavaScript

You can compare not only strings, but also objects with dates. Let's look at an example. Let us have two objects with dates that we have created through `new Date` and written into variables. Let's compare which date is greater:

`let date1 = new Date(2020, 1, 1); let date2 = new Date(2019, 1, 1); console.log(date1 > date2); // shows true`

Now let the first date be less than the second:

`let date1 = new Date(2020, 1, 1); let date2 = new Date(2021, 1, 1); console.log(date1 > date2); // shows false`

Get a date object containing the current time. Get a date object containing the noon of the current day. Compare these two objects and determine if it was already noon or not.

Get a date object containing the current time. Get a date object containing `15`th of the current month. Compare these two objects and determine if half a month has already passed or not.

← →
↑
en ru