Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript to format date value

I am trying (and failing!) to format my date output using javascript, so I am asking for some help.

The date format is 2013-12-31 (yyyy-mm-dd), but I want to display the date as 12-2013 (mm-yyyy).

I have read many posts, but I am now just confused.

Here is the call to the javascript function:

changeDateFormat($('#id_award_grant_date').val()),

Here is the javascript function:

 function changeDateFormat(value_x){


 }
like image 665
user1261774 Avatar asked Dec 20 '25 19:12

user1261774


2 Answers

What you have is just a string, so just split it and put it back together in the wanted format

var date     = '2013-12-31',
    parts    = date.split('-'),
    new_date = parts[1]+'-'+parts[0];

FIDDLE

like image 124
adeneo Avatar answered Dec 22 '25 09:12

adeneo


var d = '2013-12-31'
var yyyymmdd = d.split('-')
var mmyyyy = yyyymmdd[1]+'-'+yyyymmdd[0]; // "12-2013"
like image 38
Matt Avatar answered Dec 22 '25 10:12

Matt



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!