Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CRON expression to next DateTime with T-SQL on SQL server

I have a column that contains a CRON expression that represents how often a user has to perform a task. I would like to build a view that lists the date and things to do for a given user. But I need to calculate my next CRON occurrence in a datetime in T-SQL. How interpreted my expression CRON in SQL?

example: column value = [0 30 8 1 *?]

I would write: SELECT CrontabSchedule ( '0 30 8 1 *?', GETDATE ()) FROM dbo.UserTasks

Someone has a solution ?

like image 206
tdelepine Avatar asked Feb 18 '16 20:02

tdelepine


People also ask

What is cron expression 0 * * * *?

Meaning of cron expression 0 * * * * *? I think it means the scheduler is expected to run every seconds.

How do I create a cron job in SQL Server?

Expand SQL Server Agent, expand Jobs, right-click the job you want to schedule, and click Properties. Select the Schedules page, and then click New. In the Name box, type a name for the new schedule. Clear the Enabled check box if you do not want the schedule to take effect immediately following its creation.

What is cron expression generator?

CronMaker is a simple application which helps you to build cron expressions. CronMaker uses Quartz open source scheduler. Generated expressions are based on Quartz cron format. For your feedback send email to [email protected]. Generate cron expression.


1 Answers

There is no built in function within SQL server to genrate Next date based on Cron expression. Only way would be, implemeting cron exprssions in C# and genrate it as dll,then regsiter DLL with SQL server CLR.

Refernces: https://social.msdn.microsoft.com/Forums/en-US/3e0ebe5a-d452-4893-bcef-0a1e2520c076/convert-cron-expression-to-datetime?forum=transactsql

https://github.com/atifaziz/NCrontab/wiki/SQL-Server-Crontab

like image 191
Harish kakani Avatar answered Nov 15 '22 06:11

Harish kakani