Results 1 to 4 of 4

Thread: Compare two DateTime objects

  1. #1
    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..

  2. #2
    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

  3. #3
    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.

  4. #4
    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;
      }
    }

Similar Threads

  1. How to convert string into DateTime
    By Segvoia in forum Software Development
    Replies: 7
    Last Post: 05-03-2010, 02:55 PM
  2. Compare ArrayList of objects
    By TechGate in forum Software Development
    Replies: 5
    Last Post: 13-02-2010, 01:32 AM
  3. out-of-range datetime value
    By MobilePhoneGuru in forum Software Development
    Replies: 3
    Last Post: 09-10-2009, 10:05 AM
  4. DateTime Format String
    By Zool in forum Software Development
    Replies: 3
    Last Post: 17-07-2009, 03:20 PM
  5. SQL SELECT with DateTime
    By Coldman in forum Software Development
    Replies: 5
    Last Post: 26-02-2009, 02:36 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,946,208.57340 seconds with 17 queries