简体   繁体   中英

How to check if sql current timestamp is >= 24hours from now timestamp

Im trying to make function that checks if timestamp from database row (current_timestamp() -> for example: 2022-11-25 21:41:03) is 24 hours or more ago, thats a piece of code I have:

async function clearChannels() {
    const deleted_tos = 0;
    const response = await axios.get(`${apiurl}/get/all`);

    JSON.parse(JSON.stringify(response.data)).forEach(function(element) {
        const timestamp = element.CTS;

    });
}

I just cant figure out how to make if statement that checks if timestamp const is 24 hours ago or more from now

const timestamp = new Date(element.CTS) // milliseconds
const now = new Date() // milliseconds
const isPast24hrs = now - timestamp > (60 * 60 * 24 * 1000) // millisecond value

if(isPast24hrs) {
    // your logic goes here
}

Hope it helped

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM