Learn more about SQL Server tools

mssqltips logo

Tutorials          DBA          Dev          BI          Career          Categories          Webcasts          Whitepapers          Today's Tip          Join

Tutorials      DBA      Dev      BI      Categories      Webcasts

DBA    Dev    BI    Categories

Simplify SQL Server Database Development     ====>    Webcast Registration

SQL Server video to test what an application would do in the past or in the future

By:   |   Read Comments   |   Related Tips: More > Testing


Enter your business email address to
get free SQL Server tips.

Problem / Solution

Testing T-SQL application code that has time dependencies can be a very difficult and error prone task. By borrowing a technique from Test-Driven-Development and using a mock-time instead of the real time it becomes easy to test how a stored procedure or function would behave at some other time in the past or the future. This is done by replacing calls to getdate() from within application code with a function that returns the mock-time when run during a test.

Key Learning Items
  • How to create your own current date/time using a date in the past or future
  • Learn about CONTEXT_INFO()
Read Companion Tip

Click Here

Last Update:

next webcast button

next tip button

About the author
MSSQLTips author Andy Novick Andy Novick is a SQL Server Developer in the Boston area with 25 years of database and application development experience.

View all my tips

Post a comment or let the author know this tip helped.

All comments are reviewed, so stay on subject or we may delete your comment. Note: your email address is not published. Required fields are marked with an asterisk (*).

*Name    *Email    Email me updates 

Signup for our newsletter
 I agree by submitting my data to receive communications, account updates and/or special offers about SQL Server from MSSQLTips and/or its Sponsors. I have read the privacy statement and understand I may unsubscribe at any time.


Learn more about SQL Server tools