Changing the output of Getdate

前端 未结 4 1543
谎友^
谎友^ 2020-12-11 15:57

Is it possible to deceive SQL Server to return a different date on GetDate() without actually changing the machine date?
This would be great, since we have

相关标签:
4条回答
  • 2020-12-11 16:17
    SELECT DATEADD(dd, -7, GETDATE())
    
    0 讨论(0)
  • 2020-12-11 16:22

    No, there is not much you can do other than something like this:

    SELECT GETDATE()-7  --get date time 7 days ago
    
    0 讨论(0)
  • 2020-12-11 16:26

    You can always wrap GetDate() in a custom function and use that everywhere, although it's not an optimal solution.

    0 讨论(0)
  • 2020-12-11 16:34

    According to the documentation for getdate():

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

    Since it's derived from the OS, I don't think you can change it separately.

    0 讨论(0)
提交回复
热议问题