Support Topics Documentation Slack YouTube Blog

Query based on data difference

Hello

How can I get the rows where the createDate - currentDate is greater than 4 days

Basically I want to have a timer on the server where it regularly checks to see if there are posts made older than 4 days and delete them as they are expired by then

Thank you

Hello

I guess you can use “bulkDelete” api for removing all the expired post, let me give you some example:

async execute(){
 ....
  await Backendless.Data.of( "Posts" ).bulkDelete( `created < ${Date.now() - (4 * 24 * 60 * 60 * 1000)}` )
 ....
}

Date.now() - (4 * 24 * 60 * 60 * 1000) - this will return a timestamp of 4 days before today

here is a doc for bulkDelete https://backendless.com/docs/js/data_multiple_objects_bulk_delete.html#deleting-multiple-objects

Regards, Vlad

This is interesting way to calculate difference
Thank you for the hint