Solved

c# Help Comparining DateTimes

Posted on 2009-07-08
1
238 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
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

773 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