|
| |||||||||
| Tags: codes, coding, console, datetime, datetime objects, net, objects, syntax, timespan, timespan objec, writeline |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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.. ![]() |
|
#2
| ||||
| ||||
| 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 |
|
#3
| |||
| |||
| 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) |
|
#4
| ||||
| ||||
| 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;
}
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 11:05 AM |
| DateTime Format String | Zool | Software Development | 3 | 17-07-2009 04:20 PM |
| SQL SELECT with DateTime | Coldman | Software Development | 5 | 26-02-2009 02:36 PM |