Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Compare two DateTime objects

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 28-11-2009
Member
 
Join Date: Nov 2009
Posts: 1,292
Compare two DateTime objects
  

Hey,

I am a beginner in the technology of the coding and need some help regarding the codes. I am developing a program of .Net and wanted to compare two DateTime Object. But i have no idea of doing the same. I tried lots of technique to do so but could not succeeded so finally i came here to ask the same. So please help me to resolve the issue of DateTime Object.

Any help may be appreciated..

Reply With Quote
  #2  
Old 28-11-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: Compare two DateTime objects

Hi there,

I have a solution to your problem because i am having the same query in last week. And after doing much effort i got it from some forum so i am giving you the same.

For comparing the DateTime Object you have to use <,>, == operators or another method is to call the "DateTime.Compare()" method. And if you want the DateTime Objects duration then you have to subtract the DateTime Object directly so that you will get a TimeSpan Object which will represent the time duration of the DateTime Object

Thank You
Reply With Quote
  #3  
Old 28-11-2009
Member
 
Join Date: May 2008
Posts: 2,012
Re: Compare two DateTime objects

Hi Dude,

Comparing of DateTime Object is very easy, all you have to do is to use some of the operator or the methods to take effect. It can also tell you about the time duration but that is not our discussion part so let come to the simple example about the same

Code:
DateTime d1="Enter first Date";

DateTime d2="Enter some other Date";

if(d1>d2)
This is the basic syntax use it with your codes to take effect.
Reply With Quote
  #4  
Old 28-11-2009
Member
 
Join Date: Apr 2008
Posts: 2,005
Re: Compare two DateTime objects

Hey,

Even i have something too that i am sharing with you which will compare the two DateTime Object using switch method

Code:
DateTime original = new DateTime(2009,11,11);
DateTime compareDateTime = new DateTime(original.Year -1 , original.Month, original.Day);
switch (original.CompareTo(compareDateTime))
{
case 0 :
  Console.WriteLine("Greater");
  break;
case 1:
  Console.WriteLine("Equal");
  break;
case 2:
  Console.WriteLine("Lesser");
  break;
  }
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Compare two DateTime objects"
Thread Thread Starter Forum Replies Last Post
How to convert string into DateTime Segvoia Software Development 7 05-03-2010 02:55 PM
Compare ArrayList of objects TechGate Software Development 5 13-02-2010 01:32 AM
out-of-range datetime value MobilePhoneGuru Software Development 3 09-10-2009 10:05 AM
DateTime Format String Zool Software Development 3 17-07-2009 03:20 PM
SQL SELECT with DateTime Coldman Software Development 5 26-02-2009 02:36 PM


All times are GMT +5.5. The time now is 09:16 AM.