Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# how does comparing datetime work

using System;
public class Demo {
   public static void Main(){
      DateTime d1 = new DateTime(2019, 12, 20, 6, 20, 40);
      DateTime d2 = new DateTime(2019, 11, 20, 6, 20, 40);
      Console.WriteLine("DateTime 1 = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", d1);
      Console.WriteLine("DateTime 2 = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", d2);
      int res = DateTime.Compare(d1, d2);
      // returns equal to 0 since d1 is equal to d2
      Console.WriteLine(res);
   }
}
Comment

how to compare datetime in c#

DateTime.Compare(datetime1, datetime2);
/*
datetime1 before datetime2 = -ve
datetime1 equal datetime2 = 0
datetime1 after datetime2 = +ve
*/
Comment

C# compare date values

var target = DateTime.Parse("3/25/2020");
var todaysDate = DateTime.Today;

if(target > todaysDate)
{
    Console.WriteLine("Hello World!");
}
else 
{
    Console.WriteLine("Too Bad");
}
Comment

c# how to compare 2 dates without time

if(dateTime1.Date == dateTime2.Date)
  // or 
if (dateTime1.Date.CompareTo(dateTime2.Date))
{
}
Comment

c# compare dateTime with string

if ( DateTime.Parse(date2,CultureInfo.InvariantCulture) <=  DateTime.Parse(date1,CultureInfo.InvariantCulture))

{
  // perform some code here
}
Comment

how to compare time strings in c#

var value = "00:00:15:185";    

    if (DateTime.ParseExact(value, "HH:mm:ss:fff", CultureInfo.InvariantCulture) > 
        DateTime.ParseExact("00:00:15:000", "HH:mm:ss:fff", CultureInfo.InvariantCulture))
    {
        // logic here.  
    }
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to add skybox in unity 
Csharp :: c# access substring 
Csharp :: c# read xml tag value 
Csharp :: c# .equals vs == 
Csharp :: how to add event function from code in wpf 
Csharp :: loading player preferences unity 
Csharp :: how to change text in richtextbox wpf 
Csharp :: asp net saber ip address of client machine IIS 
Csharp :: unity make a gambeobject array 
Csharp :: Match one of 1, 2, x or X, or nothing 
Csharp :: cross thread exception in c# control 
Csharp :: c sharp convert string time into 24 hours time 
Csharp :: unity inspector draw line 
Csharp :: c# loop 2 time tables 
Csharp :: unity rigidbody freeze all rotation 
Csharp :: Get Mouse World Position 
Csharp :: only specific columns in Linq 
Csharp :: Convert integers to written numbers C# 
Csharp :: disable alt + f4 in c# forms 
Csharp :: c# tell if a class is a child or the class itself 
Csharp :: c# string to binary 
Csharp :: browser folder in wpf 
Csharp :: c# if statements 
Csharp :: android jaca how to pass a imageurl in a recyclerview adapter 
Csharp :: convert date to days c# 
Csharp :: How to set default page asp.net MVC 
Csharp :: declare prop array c# 
Csharp :: HttpClient .net Core add Certificate 
Csharp :: dbset syntax 
Csharp :: camelCase and snakeCase 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =