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

308
Views
JavaScript - Date function throwing "is not a function" error

I am very new to JavaScript and it took me some time to come up with the following function in order to get current date and subtract a year from it:

function getDate() {
    var now = new Date();
    // get current timezone specific date/time
    // timezoneoffset value converts returned offset value to milliseconds
    // get current date value - 1 year
    var dateMinusOneYear = new Date(now.getTime() - 31556952000) + (now.getTimezoneOffset() * 60000);
    var dateStr =
        ("0000" + (dateMinusOneYear.getFullYear())).slice(-4) + "-" +
        ("00" + (dateMinusOneYear.getMonth() + 1)).slice(-2) + "-" +
        ("00" + dateMinusOneYear.getDate()).slice(-2);
    return (dateStr);
}

When I invoke the function, I get the following error: TypeError: dateMinusOneYear.getFullYear is not a function

Can anyone please advise? Some might advise to not use the new Date method at all due to problematic reasons, but I have to use it specifically for some unrelated reasons.

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

0

This makes no sense at all

 new Date(now.getTime() - 31556952000) + (now.getTimezoneOffset() * 60000);

Maybe you were trying to accomplish this?

   new Date(now.getTime() - 31556952000 + now.getTimezoneOffset() * 60000);
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!