Parse String in SQL date format to Date - Node.js Date

Node.js examples for Date:Date Format

Description

Parse String in SQL date format to Date

Demo Code


Date.parseSQLDate = function (st) {
    if (st) {//from  w  ww.  j  a  v a2  s.  com
        var dregex = /(\d{2})\/(\d{2})\/(\d{4}) (\d{2}):(\d{2}):(\d{2})/;
        var dateArray = dregex.exec(st);
        return new Date(
            (dateArray[3]),
            (dateArray[2]) - 1,
            (dateArray[1]),
            (dateArray[4]),
            (dateArray[5]),
            (dateArray[6])
        );
    }
};

Related Tutorials