Last active
August 4, 2022 01:38
-
-
Save Octagon-simon/90fe11a5bb94f45e44e5ff2729d79199 to your computer and use it in GitHub Desktop.
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
| function calcDate(date1, date2){ | |
| /* | |
| * calcDate() : Calculates the difference between two dates | |
| * @date1 : "First Date in the format MM-DD-YYYY" | |
| * @date2 : "Second Date in the format MM-DD-YYYY" | |
| * return : Array | |
| */ | |
| //new date instance | |
| const dt_date1 = new Date(date1); | |
| const dt_date2 = new Date(date2); | |
| //Get the Timestamp | |
| const date1_time_stamp = dt_date1.getTime(); | |
| const date2_time_stamp = dt_date2.getTime(); | |
| let calc; | |
| //Check which timestamp is greater | |
| if (date1_time_stamp > date2_time_stamp) { | |
| calc = new Date(date1_time_stamp - date2_time_stamp); | |
| } else { | |
| calc = new Date(date2_time_stamp - date1_time_stamp); | |
| } | |
| //Retrieve the date, month and year | |
| const calcFormatTmp = calc.getDate() + '-' + (calc.getMonth() + 1) + '-' + calc.getFullYear(); | |
| //Convert to an array and store | |
| const calcFormat = calcFormatTmp.split("-"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment