Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3626862
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:48:57+00:00 2026-05-18T23:48:57+00:00

When we do development/QA we often need to pretend that current date/time is something

  • 0

When we do development/QA we often need to pretend that current date/time is something other than now. It is pretty common for us to have some sort of logic that relies on date.

Simple example: say a product in the store is available between Dec 15 2010 to Jan 3 2011. These two dates would be stored in DB, and code would compare it to DateTime.Now. This obviously needs to be [unit]tested somehow. Question is how?

So far we just added a custom Date object and attempted to enforce using Date.Now instead of DateTime.Now, which does not cover any third party code that may rely on current date and is also feels super lame.

I wonder is there is a bit more kosher way of handling date override without changing system date in Windows.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T23:48:58+00:00Added an answer on May 18, 2026 at 11:48 pm

    For unit testing I would recommend you to take a look at Microsoft Moles, an isolation framework that would let you replace a call to DateTime.Now with your own delegate which could return any date you wanted.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a not-so-small class under development (that it changes often) and I need
Often multiple applications share a large codebase of libraries that change often in development.
During development I have to clear cache in Firefox all the time in order
In web development, I often find I need to format and print various arrays
For various reasons (code review mostly) I need to switch from current development branch
In our development environment each developer has their own dev server. Often times they
I am in the process of setting up a complete web-development environment. For now,
For some time now I've been storing my connection and app settings in an
The title is not very clear. What I actually need to do often is
I've often read that corporations will save millions once Internet Explorer 6 is finally

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.