Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
Compare if 2 dates are the same in javascript

var beginningTime = moment('1635750314812', 'YYYY/MM/DD'); // Today date
var endTime = moment(undefined, 'YYYY/MM/DD') // Today date
console.log(beginningTime.isSame(endTime)); //expect true
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>

I am using moment js to get if 2 date are the same using the above pattern. But now i get false instead of true. How to solve the issue?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Instead of formatting the beginningTime and endTime separately, you should take a look at the 'granularity' argument for isSame().

I made a few adjustments to your code for it to work, and also look cleaner.

var beginningTime = moment(1635750314812); // Today date (from timestamp)
var endTime = moment() // Today date
console.log(beginningTime.isSame(endTime, 'day')); //expect true
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>

It first simply creates a moment of your timestamp and a moment of right now, whenever now is. Then it will compare the two moments with a granularity of a day, effectively checking if the day and everything bigger (month, year) is the same.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!