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

262
Views
how to format date pulled from database(inserted as new Date() )

I'm not so sure what's the proper way to insert date into the database, but I'm using new Date().

So I get date format like this when I query from the database:

2021-09-24T12:38:54.656Z

Now I realized that date format is not so user-friendly. So I'm trying to convert it if possible standard readable format like this:

Sept 25 2015, 8:00 PM

I tried using toLocaleString() to my date pulled from db but it won't work probably if I got it correctly pulled date from the db is already a string?

Is there a workaround for this so that I don't need to change how I enter date to my db?

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

0

const date = moment("2021-09-24T12:38:54.656Z").format('MMM D YYYY, h:mm a')
console.log(date)
<script src="https://momentjs.com/downloads/moment.min.js"></script>

use momentjs

You can find format method and apply as you desire

https://momentjs.com/

about 4 years ago · Juan Pablo Isaza Report

0

I think it is better to store in DB as UTC 00 value and you are doing it right now.

When you retrieve it, you will be getting a string value something like, 2021-09-24T12:38:54.656Z. On the UI you can easily convert it to date variable in JS using,

const dateVar = new Date("2021-09-24T12:38:54.656Z");
console.log(dateVar.toLocaleString());

If you want more date formatting other than the inbuild solutions like toLocaleString you can use date libraries like moment.js

about 4 years ago · Juan Pablo Isaza Report

0

You'd need to create a Date object from the timestamp string like this.

let date = new Date('2021-09-24T12:38:54.656Z');

Then you can use toLocaleString, toLocaleDateString, toDateString, or toString as you see fit.

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!