Nodejs Utililty Methods Date Compare

List of utility methods to do Date Compare

Description

The list of methods to do Date Compare are organized into topic(s).

Method

isSameDate(d)
Date.prototype.isSameDate = function (d) {
    var tDate = new Date(this.getFullYear(), this.getMonth(), this.getDate());
    var pDate = new Date(d.getFullYear(), d.getMonth(), d.getDate());
    return tDate == pDate
isSameDateAs(pDate)
Date.prototype.isSameDateAs = function (pDate) {
    return (
      this.getFullYear() === pDate.getFullYear() &&
      this.getMonth() === pDate.getMonth() &&
      this.getDate() === pDate.getDate()
    );
compare(b)
var debug = require('debug')('util/date.js');
Date.prototype.compare = function(b){
  if(this.getFullYear() != b.getFullYear()){
    return false;
  }else{
    if(this.getMonth() != b.getMonth()){
      return false;
    }else{
      if(this.getDate() != b.getDate()){
...
date()
Date.prototype.date = function () {
    return String(this.getFullYear()) + "-" + (this.getMonth() + 1).zfill(2) + "-" + this.getDay().zfill(2);
};
date()
Date.prototype.date = function(){
  var yyyy = this.getFullYear().toString();
  var mm = this.getFullMonth().toString(); 
  var dd  = this.getDate().toString();
  return mm+'-'+dd+'-'+yyyy;
};
date()
Date.prototype.date = function() {
  var y = this.getFullYear(),
      m = this.getMonth(), 
      d = this.getDate();
  if(d < 10) {d = "0" + d;}
  if(m < 10) {m = "0" + m;}
  return "" + y + "-" + m + "-" + d;      
date()
Date.prototype.date = function(){
  var yyyy = this.getFullYear().toString();
  var mm = (this.getMonth()+1).toString(); 
  var dd  = this.getDate().toString();
  return mm+'-'+dd+'-'+yyyy;
};