1

We have a bunch of T-SQL scripts dependent on today's date and when they run. If one doesn't run on the week it should, we end up temporarily setting the system time a day before, run the script, then set it back.

Is there anyway to temporarily set the system date for a script without changing the original script, like when you execute it or only for that session?

Zachary Scott
  • 20,968
  • 35
  • 123
  • 205

2 Answers2

1

You could store the actual date in a table / temp table. THen retrieve or update that date rather then making a call to GetDate().

JonH
  • 32,732
  • 12
  • 87
  • 145
  • Problem is the existing scripts call getdate() and we cannot change the existing scripts. – Zachary Scott Sep 13 '10 at 18:54
  • @Dr Zim - but if you run the script call getdate and then insert that date in the table you can then check. If there is a date to use the date in the table rather then getdate. – JonH Sep 13 '10 at 19:07
  • Without changing the existing code, how would you get the original code to use the date in a table? – Zachary Scott Sep 15 '10 at 15:06
0

I've found an answer by someone else, here I share it: "The date is tied to the OS date and time. See here: http://msdn.microsoft.com/en-us/library/ms188383.aspx".

You could refer to this other question Simulate current date on a SQL Server instance?

Community
  • 1
  • 1
Andres Calle
  • 257
  • 1
  • 3
  • 11