Skip to content

Instantly share code, notes, and snippets.

@stiekel
Created May 20, 2016 07:06
Show Gist options
  • Save stiekel/ba7efdb2b0c3545270f45ccdba06b437 to your computer and use it in GitHub Desktop.
Save stiekel/ba7efdb2b0c3545270f45ccdba06b437 to your computer and use it in GitHub Desktop.
JavaScript get previous work day
function getPrevWorkDay (t) {
if(!t) t = new Date();
if( !(t instanceof Date) ) t = new Date(t);
var prevDay = new Date( t.getTime());
do {
prevDay = new Date( prevDay.getTime() - 86400000 );
} while( -1 !== [0, 6].indexOf(prevDay.getDay()) );
return prevDay;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment