Click here to Skip to main content
15,910,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
function ConvertDate(dateString) {
    var datet;
    if (dateString != undefined) {

        var date = new Date(parseInt(dateString.replace(/\/Date\((\d+)\)\//, '$1')));
        var month = date.getMonth() + 1;
        if (month < 10)
            month = '0' + month;
        var day = date.getDate();
        if (day < 10)
            day = '0' + day;
        var year = date.getFullYear();
        var datet = month + "/" + day + "/" + year;
        return datet;
    }
    else {
        datet = String.empty();
        return false;
    }

}



It works fine but i wanted to ask if someone could optimize it or provide an alternative.
Posted

1 solution

A simple specification would have been more helpful, but how I see, you want to format a date.
You can use this JQuery plugin: http://archive.plugins.jquery.com/project/jquery-dateFormat[^]

SQL
function ConvertDate(dateString) {
    if (dateString && $.trim(dateString) != "") {
        return $.format.date(dateString.replace(/\/Date\((\d+)\)\//, '$1'), "MM/dd/yyyy");
    } else {
        return false;
    }
}
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900