The CreatorCon Call for Content is officially open! Get started here.

Expiry Date of the certificate is showing wrong

roomawakar
Tera Contributor

Hi All,

 

I have noticed an issue with the field called -"Expiry" in the Certificate table where two different certificates having the same date, but one shows 5Days from now and another shows 6Days from now.

 

For example: If the Expiry is on 30-04-2025, one certificate shows '5d from now' and another certificate shows '6d from now'. Screenshot attached. There is no BR and any script script which is setting that Expiry date on the certificate table. It is being set manually.

 

Because of this issue, one of the scheduled job is not working properly.

Can anyone suggest why it is showing as incorrect and how can it be rectified. 

 

Thanks,

Rooma

1 ACCEPTED SOLUTION

VikMach
Mega Sage

Hi @roomawakar - That is not an issue. The "Expiry" field (or any date time field) is comparing the date and time "both" with nowDateTime(). It is comparing with your System Date Time.
Explained below to understand better.

// Define today's date and time
var today = new GlideDateTime('2025-04-25 19:56:47');

// Define the two target dates
var targetDate1 = new GlideDateTime('2025-04-30 12:50:04');
var targetDate2 = new GlideDateTime('2025-04-30 21:48:09');

// Calculate the difference in milliseconds
var duration1 = GlideDateTime.subtract(today, targetDate1);
var duration2 = GlideDateTime.subtract(today, targetDate2);

// Convert milliseconds to days
var daysLeft1 = Math.floor(duration1.getNumericValue() / (1000 * 60 * 60 * 24));
var daysLeft2 = Math.floor(duration2.getNumericValue() / (1000 * 60 * 60 * 24));

// Log the results
gs.info('Days left from today to reach 30th April 2025, 12:50:04: ' + daysLeft1 + ' days');
gs.info('Days left from today to reach 30th April 2025, 21:48:09: ' + daysLeft2 + ' days');

 

Vikas1_0-1745592013131.png

 


Hope this helps!
Let me know if it was helpful.

 

PS - Since you have not mentioned what your scheduled job is doing. I can't suggest anything. If you let us know what you wish to achieve by this may be someone can help. Cheers!

Regards,
Vikas K

View solution in original post

1 REPLY 1

VikMach
Mega Sage

Hi @roomawakar - That is not an issue. The "Expiry" field (or any date time field) is comparing the date and time "both" with nowDateTime(). It is comparing with your System Date Time.
Explained below to understand better.

// Define today's date and time
var today = new GlideDateTime('2025-04-25 19:56:47');

// Define the two target dates
var targetDate1 = new GlideDateTime('2025-04-30 12:50:04');
var targetDate2 = new GlideDateTime('2025-04-30 21:48:09');

// Calculate the difference in milliseconds
var duration1 = GlideDateTime.subtract(today, targetDate1);
var duration2 = GlideDateTime.subtract(today, targetDate2);

// Convert milliseconds to days
var daysLeft1 = Math.floor(duration1.getNumericValue() / (1000 * 60 * 60 * 24));
var daysLeft2 = Math.floor(duration2.getNumericValue() / (1000 * 60 * 60 * 24));

// Log the results
gs.info('Days left from today to reach 30th April 2025, 12:50:04: ' + daysLeft1 + ' days');
gs.info('Days left from today to reach 30th April 2025, 21:48:09: ' + daysLeft2 + ' days');

 

Vikas1_0-1745592013131.png

 


Hope this helps!
Let me know if it was helpful.

 

PS - Since you have not mentioned what your scheduled job is doing. I can't suggest anything. If you let us know what you wish to achieve by this may be someone can help. Cheers!

Regards,
Vikas K