Skip to content

Commit e1f2210

Browse files
MYaswanth28Lacah
andauthored
Create GlideDateTime_DaysUntilFutureDate (#164)
* Create GlideDateTime_DaysUntilFutureDate This syntax macro provides a reusable snippet for calculating the number of days between the current date and a specified future date. It initializes the current date, sets a future date, calculates the difference in milliseconds, converts the difference to days, and logs the result. This can be useful for deadline tracking, event planning, and other time-based calculations. * Rename GlideDateTime_DaysUntilFutureDate to GlideDateTime/DaysUntilFutureDate * Rename DaysUntilFutureDate to DaysUntilFutureDate.js --------- Co-authored-by: Laszlo <[email protected]>
1 parent 9a88ddb commit e1f2210

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

GlideDateTime/DaysUntilFutureDate.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Initialize the current date and time
2+
var currentDate = new GlideDateTime();
3+
4+
// Set the future date (e.g., '2023-12-31 00:00:00')
5+
var futureDate = new GlideDateTime('2023-12-31 00:00:00');
6+
7+
// Calculate the difference in milliseconds
8+
var diff = GlideDateTime.subtract(futureDate, currentDate);
9+
10+
// Convert the difference to days
11+
var daysUntil = Math.floor(diff.getNumericValue() / (1000 * 60 * 60 * 24));
12+
13+
// Log the result
14+
gs.info('Days until future date: ' + daysUntil);

0 commit comments

Comments
 (0)