Question

I want to run a scheduled job every 10 minutes which will do the following: Check the table records and delete those who hasn't been updated for 10 minutes.

How is it possible to get the current server date in javascript in order to compare it?

Was it helpful?

Solution

Use the JavaScript Date object. Just creating a new Date object without parameters will give you the server date and time. It will of course be in GMT as all the servers in Azure run on GMT. However, be aware of clock drift. Each of the servers could be slightly off from one another time wise, so it may not be exact if comparing times across servers.

var cutOfDate = new Date();

You could also load up one of the JavaScript data libraries like Moment or something like that as well if you need to do a lot of date formatting or evaluations.

Another option is to simply have a stored procedure that is called to perform your clean up for you. The stored procedure could then use the SQL GETDATE() to determine the current date and do the deletes based on that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top