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

226
Views
How to convert JSON Date to Month in JavaScript

I have JSON Data from my Appscript REST API, how can I convert the date to be a month in number eg if the date contains 01 I only obtain 1/or instead of "2020-01-15T22:00:00.000Z

Here is the data sample below:

{
"Employee Name":"Ntombi  Hlatshwayo",
"Issueing Manager":"Nomsa Nxumalo",
"Type Of A Warning":"Insubordination Final",
"Date":"2020-09-15T22:00:00.000Z",
"Current Date":"2021-11-02T12:24:32.428Z",
 "Status":413
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use the Date() constructor to parse the dates since they are in ISO format, then use getUTCMonth() to get the month index. The month number will be one greater than this.

You can also use String.split() to get the same value.

let o = {
    "Employee Name":"Ntombi  Hlatshwayo",
    "Issueing Manager":"Nomsa Nxumalo",
    "Type Of A Warning":"Insubordination Final",
    "Date":"2020-09-15T22:00:00.000Z",
    "Current Date":"2021-11-02T12:24:32.428Z",
     "Status":413
}

function getMonthFromISODate(dt) {
   return new Date(dt).getUTCMonth() + 1;
}
 
console.log('Using Date()');
for (let dt of [o.Date, o['Current Date']]) { 
    console.log(`Date: ${dt}, Month: ${getMonthFromISODate(dt)}`);
}

function getMonthFromISODateII(dt) {
   return +dt.split('-')[1];
}
 
console.log('Using String.split()');
for (let dt of [o.Date, o['Current Date']]) { 
    console.log(`Date: ${dt}, Month: ${getMonthFromISODateII(dt)}`);
}
.as-console-wrapper { max-height: 100% !important; top: 0; }

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!