Nodejs Date to MySQL Date Format toMysqlDateTime()

Here you can find the source of toMysqlDateTime()

Method Source Code

Date.prototype.toMysqlDateTime = function(){
    return this.getUTCFullYear() + '-' + (1 + this.getUTCMonth()) + '-' + this.getUTCDate() + ' ' + this.getUTCHours() + ':' + this.getUTCMinutes() + ':' + this.getUTCSeconds();
}

Related

  1. toMysqlFormat()
    var twoDigits = function (d) {
        if (0 <= d && d < 10) {
          return '0' + d.toString();
        if (-10 < d && d < 0) {
          return '-0' + (-1 * d).toString();
        return d.toString();
    };
    ...
    
  2. toMysqlFormat()
    function twoDigits(d) {
        if (0 <= d && d < 10) return "0" + d.toString();
        if (-10 < d && d < 0) return "-0" + (-1 * d).toString();
        return d.toString();
    Date.prototype.toMysqlFormat = function() {
        return this.getUTCFullYear() + "-" + twoDigits(1 + this.getUTCMonth()) + "-" + twoDigits(this.getUTCDate()) + " " + twoDigits(this.getUTCHours()) + ":" + twoDigits(this.getUTCMinutes()) + ":" + twoDigits(this.getUTCSeconds());
    };
    module.exports = Date.prototype.toMysqlFormat;
    ...
    
  3. toMysqlFormat()
    var dateParser={};
    function twoDigits(d) {
        if(0 <= d && d < 10) return "0" + d.toString();
        if(-10 < d && d < 0) return "-0" + (-1*d).toString();
        return d.toString();
    Date.prototype.toMysqlFormat = function() {
        return this.getUTCFullYear() + "-" + twoDigits(1 + this.getUTCMonth()) + "-" + twoDigits(this.getUTCDate()) + " " + twoDigits(this.getUTCHours()) + ":" + twoDigits(this.getUTCMinutes()) + ":" + twoDigits(this.getUTCSeconds());
    };
    ...
    
  4. toMysqlFormat()
    function twoDigits(d) {
      if(0 <= d && d < 10) return "0" + d.toString();
      if(-10 < d && d < 0) return "-0" + (-1*d).toString();
      return d.toString();
    Date.prototype.toMysqlFormat = function() {
      return this.getFullYear() + "-" + twoDigits(1 + this.getMonth()) + "-" + twoDigits(this.getDate()) + " " + twoDigits(this.getHours()) + ":" + twoDigits(this.getMinutes()) + ":" + twoDigits(this.getSeconds());
    };