Conversion of Epoch

SN_Learn
Kilo Patron
Kilo Patron

Hi All,

 

function convertDateToEpoch(vDate) {
    epoch = '';
    vDateTmp = new GlideDateTime(vDate).getNumericValue() / 1000;
    epoch = (Math.round((vDateTmp * Math.pow(10, 0)).toFixed(0 - 1)) / Math.pow(10, 0)).toFixed(0);
    return epoch;
}
//* Epoch conversion
var ObjDate = new GlideDateTime();
var convertedFromEpoch = convertDateToEpoch(ObjDate);

gs.log(convertedFromEpoch);

 

By using the above current epoch could be found. But I want only the epoch which was at the start of the day.

Example:  Friday, July 21, 2023 12:00:00 AM, epoch value is 1689897600
Similarly, for the next day, it will be + 86,400 giving epoch 1,689,984,000 which is Saturday, July 22, 2023 12:00:00 AM

At any moment of time in the day, it should get the current epoch and convert it into that respective day's 12:00:00 AM epoch.

 

The output should be :

21st July 2023:  1689897600[on any moment of this day it should return only this value as output]

22nd July2023:  1689984000[on any moment of this day it should return only this value as output]

and so on...

Could anyone please assist in how could we achieve that? Thanks.

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.
0 REPLIES 0