Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert MySQL date format to DD/MM/YY date format using Javascript

Tags:

javascript

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.

like image 591
Sarah Macey Avatar asked Nov 14 '25 09:11

Sarah Macey


2 Answers

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>
like image 117
Sankar Krishnamoorthy Avatar answered Nov 17 '25 00:11

Sankar Krishnamoorthy


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 );
like image 25
Max Kroshka Avatar answered Nov 16 '25 23:11

Max Kroshka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!