Skip to content

Instantly share code, notes, and snippets.

@sergiks
Created February 11, 2019 11:53
Show Gist options
  • Save sergiks/2da3e3b93ff98e3b05d0b80fa6198cf3 to your computer and use it in GitHub Desktop.
Save sergiks/2da3e3b93ff98e3b05d0b80fa6198cf3 to your computer and use it in GitHub Desktop.
JS function to get nearest end of week date time as a YYY/MM/DD HH:ii:ss string
/**
* returns date-time of the nearest week end
* as a string "YYYY/MM/DD HH:ii:ss"
*/
function getEndOfWeek() {
const D = new Date();
D.setDate(D.getDate() - D.getDay() + (D.getDay() ? 7 : 0));
D.setHours(23, 59 - D.getTimezoneOffset(), 59, 0);
return D.toISOString().slice(0, 19).replace('T', ' ').replace(/-/g,'/');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment