Last active
October 15, 2018 10:59
-
-
Save mhingston/645010b6e528091508283269f01fe12e to your computer and use it in GitHub Desktop.
Smart date (SQL)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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