Skip to content

Instantly share code, notes, and snippets.

@mhingston
Last active October 15, 2018 10:59
Show Gist options
  • Save mhingston/645010b6e528091508283269f01fe12e to your computer and use it in GitHub Desktop.
Save mhingston/645010b6e528091508283269f01fe12e to your computer and use it in GitHub Desktop.
Smart date (SQL)
const toSmartDate = (date) =>
{
const year = date.getFullYear() * 10000;
const month = (date.getMonth()+1) * 100;
const day = date.getDate();
return year + month + day;
}
const fromSmartDate = (smartDate) =>
{
const date = new Date();
smartDate = smartDate.toString();
const year = parseInt(smartDate.substring(0, 4));
const month = parseInt(smartDate.substring(4, 6))-1;
const day = parseInt(smartDate.substring(6, 8));
date.setFullYear(year, month, day);
date.setHours(0, 0, 0, 0);
return date;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment