evert / TypeScript accurate date difference calculator
0 likes
0 forks
1 files
Last active 2 years ago
| 1 | // https://stackoverflow.com/a/49201872 |
| 2 | const calcDateDifference = ( |
| 3 | start: string | Date, |
| 4 | end: string | Date |
| 5 | ): { year: number; month: number; day: number } => { |
| 6 | // Convert to true dates without time |
| 7 | let startDate = new Date(new Date(start).toISOString().substring(0, 10)); |
| 8 | let endDate = new Date( |
| 9 | (end ? new Date(end) : new Date()).toISOString().substring(0, 10) |
| 10 | ); |
Newer
Older