prasad Khanna
prasad Khanna

Reputation: 11

convert the date into different format jquery/javascript

function loadTable() { //function 
    var reportedFromDate = document.IssueForm.reportedFromDate.value; //getting value from input field
    alert(reportedFromDate); //displays dd-mm-yy 31-02-13
}

I want to convert it as 31-FEB-13

Upvotes: 0

Views: 613

Answers (2)

Sagar Dalvi
Sagar Dalvi

Reputation: 200

check following snippet :

  function loadTable() { //function 
        var reportedFromDate = document.IssueForm.reportedFromDate.value; 
        alert(reportedFromDate);  // your format
        var parts=reportedFromDate.split("-");
        var date=parts[0];
        var month=parts[1];
        var year=parts[2];

        var mon=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEPT","OCT","NOV","DEC"];
        var m=parseInt(month);
        alert( date +"-"+mon[m-1]+"-"+year); // required format
    }

Upvotes: 1

Sudip
Sudip

Reputation: 2051

You need to follow some steps:

1. Create one array of months like 
var months = ["JAN","FEB"....,"DEC"];
2. Split the date with (-) seperator
3. Take the 1st index (not 0) and search through the Array (months)
4. Display the formatted date.

Upvotes: 0

Related Questions