Solved

c# Help Comparining DateTimes

Posted on 2009-07-08
1
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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