Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

c# Help Comparining DateTimes

Posted on 2009-07-08
1
Medium Priority
?
243 Views
Last Modified: 2012-05-07
I need to check a DateTime variable and evaluate whether it is more than a day older then the current datetime.

Any ideas on how to accomplish this.
0
Comment
Question by:Prysson
1 Comment
 
LVL 4

Accepted Solution

by:
mysteriousguy earned 2000 total points
ID: 24806500
Simply substract the two DateTimes and evaluate if the resulting TimeSpna is greater than one day.
DateTime dateTimeToCheck = new DateTime(2009, 7, 2,7,0,0);
TimeSpan difference = DateTime.Now - dateTimeToCheck;
bool moreThanOneDay = difference > TimeSpan.FromDays(1);
MessageBox.Show(moreThanOneDay ? "true": "false");

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question