Change Getdate Output

Is it possible to trick SQL Server into returning another date to GetDate() without actually changing the machine date?
That would be great, since we have a database with old data, and I'm trying to check out some queries that use getdate ().
I can change the date of the machine, but it brings some other problems with other applications ...
Any tips?
Thanks!

+5
source share
4 answers

According to the documentation for getdate () :

This value is obtained from the operating system of the computer on which the instance of SQL Server is running.

Since it is obtained from the OS, I do not think you can change it separately.

+8
source

You can always wrap GetDate() in a user-defined function and use it everywhere, although this is not an optimal solution.

+4
source

No, you can do nothing but this:

 SELECT GETDATE()-7 --get date time 7 days ago 
+1
source
 select dateadd(dd, -7 getdate()) 
0
source

Source: https://habr.com/ru/post/902234/


All Articles