Solved

c# Help Comparining DateTimes

Posted on 2009-07-08
1
235 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 500 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
What does this  TN Map<T, TN>(T src) mean? 5 31
asp.net mvc5 3 35
Chat Room 1 18
Create XML 5 29
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…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now