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

200
Views
Get Day Name from Date in JS

enter image description here

Hello guys, i need some help over here, hope that you can provide me the solution.

How can i transform this Date format to a Format that shows the names of the days.

I know that i can use something like this but i dont know how to add that when im mapping data from an object or array.

let getDayName = (dateStr, locale) => {
    let date = new Date(dateStr);
    // console.log(date.toLocaleDateString(locale, { weekday: 'long' }));
    return date.toLocaleDateString(locale, { weekday: 'long' });
  };

 let dateStr = date;

enter image description here

enter image description here

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

0

You can add another map declaration and do it there like so:

.filter(() => {})
.map((item) => {
    item.dt_txt = getDayName(item.dt_txt);
    return item;
})
.map(() => {})
about 4 years ago · Juan Pablo Isaza Report

0

You are on the right track. Only thing missing is, that you need to call your function getDayName() and provide sufficient arguments.

Here an example:

const array = ["2022-05-30 18:00:00", "2022-05-30 17:00:00", "2022-05-25 18:00:00"]

const getDayName = (dateStr, locale) => {
  let date = new Date(dateStr);
  return date.toLocaleDateString(locale, { weekday: 'long' });
};

const output = array.map(dateStr => getDayName(dateStr, "en-GB"))

console.log(output)
.as-console-wrapper { max-height: 100% !important; top: 0; }

In your case you are already mapping using map(), therefore you would just need to call your function within the callback of map():

<!-- other code... -->
<div className="fd-day">
    <h1>{getDayName(item.dt_txt, "en-GB")}</h1>
</div>
<!-- some more code... -->

instead of

<!-- other code... -->
<div className="fd-day">
    <h1>{item.dt_txt}</h1>
</div>
<!-- some more code... -->

Of course you can adjust the locale to whatever fits your needs.

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!