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 a database with old data and I'm trying to test some queries that use getdate().
I can change my machine date but that brings some other problems with other applications...
Any tips?
Thanks!
The GETDATE() function returns the current database system date and time, in a 'YYYY-MM-DD hh:mm:ss.mmm' format.
You can specify the format of the dates in your statements using CONVERT and FORMAT. For example: select convert(varchar(max), DateColumn, 13), format(DateColumn, 'dd-MMM-yyyy')
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.
You can always wrap GetDate()
in a custom function and use that everywhere, although it's not an optimal solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With