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

151
Views
Moment not comparing weekly date correctly?

here is the example. i have it always return true

const lastDiscountCode = moment(202352,"YYYYWW");
const currentWeek = moment().format("YYYYWW");
alert(moment(lastDiscountCode).isBefore(moment(currentWeek)));
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

In moment(202352, "YYYYWW").format("YYYYWW") what you enter inside the moment function takes the data and converts it into date format first, and then that date is formatted into 'YYYYWW'. So what you should be doing is enter a date inside the moment and then format it into 'YYYYWW'

const lastDiscountCode = moment('2024-09-28').format("YYYYWW");
const currentWeek = moment().format("YYYYWW");
console.log(currentWeek);      // "202204"
console.log(lastDiscountCode); // "202439"
alert(moment(lastDiscountCode).isBefore(moment(currentWeek))); // false

about 4 years ago · Juan Pablo Isaza Report

0

You have to use .format("YYYYWW") on lastDiscountCode :

const lastDiscountCode = moment(202352,"YYYYWW").format("YYYYWW");
const currentWeek = moment().format("YYYYWW");
console.log(moment(lastDiscountCode).isBefore(moment(currentWeek)));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.2.1/moment.min.js"></script>

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!