1

I have a creation_date displayed in my database in this format

2014-02-03 15:59:07

but when I'm displaying it in my page the format is

2014-02-10T18:16:43.000Z

What do I need to do to display it properly? I'm using JavaScript. Thanks

0

3 Answers 3

3
date = new Date("2014-02-10T18:16:43.000Z");

and then use some of Date methods, for example

date.toDateString() will show "Mon Feb 10 2014", or you could format by yourself by composing your own format. Like:

 formattedDate = date.getDate()+"."+(date.getMonth()+1)+"."+date.getFullYear();

and output will be "10.2.2014"

Sign up to request clarification or add additional context in comments.

2 Comments

Forget what I said, I wasn't paying attention... +1
Thanks, I displayed it with date = new Date("2014-02-10T18:16:43.000Z"); date.toLocaleString() :)
0

First select date data as unix timestamp multiplying 1000 to get miliseconds;

SELECT UNIX_TIMESTAMP(your_date_col) * 1000 AS ts ...

Then get it to Javascript (assuming that you use PHP):

var date2display = new Date(<?=$row['ts']?>);

Comments

0

Get Date from MongoDB

InvoiceModel.find({})
    .sort({ dueDate: -1 })
    .exec((err, data) => {
      if (!err) {
        console.log(data[0].dueDate);
        const dt = data[0].dueDate.toDateString();
        const date = new Date(dt);
        console.log(dt);

        console.log(date.getDate());
        console.log(date.getMonth() + 1);
        console.log(date.getFullYear());
       
        res.json({ status: 200, message: " Invoice are received", data: data });
      } else {
        res.json({ status: 401, message: err, data: {} });
      }
    });
 

1 Comment

Please add some information/description about your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.