Skip to content

Instantly share code, notes, and snippets.

@codexico
Created January 28, 2013 16:44
Show Gist options
  • Save codexico/4657089 to your computer and use it in GitHub Desktop.
Save codexico/4657089 to your computer and use it in GitHub Desktop.
date utils
//http://stackoverflow.com/questions/7388001/javascript-regex-to-validate-date
//http://jsfiddle.net/mplungjan/Mqh8D/
var isDate = function (str) {
var parms = str.split(/[\.\-\/]/);
var yyyy = parseInt(parms[2],10);
var mm = parseInt(parms[1],10);
var dd = parseInt(parms[0],10);
var date = new Date(yyyy,mm-1,dd,0,0,0,0);
return mm === (date.getMonth()+1) && dd === date.getDate() && yyyy === date.getFullYear();
}
var stringToDate = function (str) {
var parms = str.split(/[\.\-\/]/);
var yyyy = parseInt(parms[2],10);
var mm = parseInt(parms[1],10);
var dd = parseInt(parms[0],10);
return new Date(yyyy,mm-1,dd,0,0,0,0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment