Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

get diff btw datetimes two C#

 int totalDays = Convert.ToInt32((DateTime.UtcNow.Date - myDateTime.Date).TotalDays);
Comment

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

PREVIOUS NEXT
Code Example
Csharp :: ? operator 
Csharp :: reverse linked list 
Csharp :: c# remove everything after last slash 
Csharp :: Oculus Unity button press 
Csharp :: unity scroll rect to bottom 
Csharp :: c# dictionary with dictionary as value 
Csharp :: string to array c# 
Csharp :: sum the digits in c# 
Csharp :: listview imagelist c# 
Csharp :: color32 unity 
Csharp :: delay activity in uipath 
Csharp :: how to fix on Input.GetMouseButtonDown(0) conting as ui 
Csharp :: fluent api 
Csharp :: c# add strings 
Csharp :: player input manager join manually 
Csharp :: combine two arraylist c# 
Csharp :: c# while loop 
Csharp :: c# xmldocument from file 
Csharp :: .net json result status code not working 
Csharp :: IsInstanceOf nunit 
Csharp :: batchblock timeout 
Csharp :: c# listview filter contains 
Csharp :: conncet oracle database in c# visual studio 
Csharp :: C# order a sorted list by key 
Csharp :: how to check if a file is running in c# 
Csharp :: windows forms webbrowser refresh 
Csharp :: c# enum to list of strings 
Csharp :: serial begin 
Csharp :: Count the Number of Duplicate Characters 
Csharp :: factorial of number 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =