include_file custom template
Custom Template - include_file
$line
is current line of code
$index
is current line index of code
1 | <table> |
index | contents line |
---|---|
1 | // global variables |
2 | const toMatch = new Date('2022-12-01T09:30:20'); |
3 | let data = `date to match: ${toMatch} `; |
4 | document.getElementById('variables').innerHTML = data; |
5 | |
6 | // method 1 using timestamp |
7 | |
8 | const yourDate = toMatch.getTime(); //Get the timestamp |
9 | const today = Date.now(); |
10 | // 2 days in millisecond |
11 | const day = 60 * 60 * 1000 * 24 * 2; |
12 | data = ` |
13 | today: ${today} |
14 | yourDate: ${yourDate} |
15 | 2 days in millisecond: ${day} |
16 | today - yourDate: ${today - yourDate} |
17 | is greater than 2 days: ${today - yourDate > day ? 'true' : 'false'}`; |
18 | document.getElementById('timestamp').innerHTML = data; |
19 | |
20 | // method 2 using hours |
21 | const now = new Date(); |
22 | |
23 | const msBetweenDates = Math.abs(toMatch.getTime() - now.getTime()); |
24 | |
25 | // 👇️ convert ms to hours min sec ms |
26 | const hoursBetweenDates = msBetweenDates / (60 * 60 * 1000); |
27 | |
28 | data = ` |
29 | hoursBetweenDates: ${hoursBetweenDates} |
30 | date is within 24 hours: ${ |
31 | hoursBetweenDates < 24 ? 'true' : 'false' |
32 | } |
33 | date is greater than 48 hours: ${ |
34 | hoursBetweenDates > 48 ? 'true' : 'false' |
35 | } |
36 | `; |
37 | document.getElementById('hours').innerHTML = data; |
38 | |
39 | // unused |
40 | function _isOverEighteen(year = 0, month = 0, day = 0) { |
41 | var now = parseInt(new Date().toISOString().slice(0, 10).replace(/-/g, '')); |
42 | var dob = year * 10000 + month * 100 + day * 1; // Coerces strings to integers |
43 | |
44 | return now - dob > 180000; |
45 | } |
46 |