4

I was wondering how I would go about converting the SQL timestamp format (2016-04-30T01:19:45.000Z) to a standard date format like (30/04/2016) using Javascript/front-end-technology.

Thanks in advance.

2
  • 2
    first do this var d = new Date(mysqldate) do this d.getDate() which return date of month than d.getMonth() and than get year with d.getFullYear() Commented Apr 30, 2016 at 2:42
  • 1
    i hope this work it's plain js Commented Apr 30, 2016 at 2:43

2 Answers 2

9

Hope this helps. This can be achieved in multiple ways - pure JavaScript, jQuery, Angular etc., As well it requires bit of tweaking based on your requirement. Do let me know if this helps

<script>
        var myDate = new Date('2010-10-11T00:00:00+05:30');
        alert((myDate.getMonth() + 1) + '/' + myDate.getDate() + '/' + myDate.getFullYear());
    </script>
Sign up to request clarification or add additional context in comments.

2 Comments

Incredible! Thank you! :)
my bootstrap datepicker didn't like the dates unless they were padded with leading zeros. I modified your solution which solved my issue. thanks.
4

It depends on how many operations you want to do. If it is more than one, then i would recommend using a library like momentJS. It makes timestamp conversion very simple. See example below.

MySQL date string:

var sqlDate = new Date('2016-04-30T01:19:45.000z');
var now = moment(sqlDate).format('l');
console.log( now );

1 Comment

Thanks! I've got quite a few libraries running already because I've been getting a bit lazy so I'm trying to avoid anymore - but regardless thank you for your response. :)

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.