Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

asp net c# compare date to current

string date = "01/04/2013";
                DateTime myDate = DateTime.ParseExact(date, "dd/MM/yyyy",
                                           System.Globalization.CultureInfo.InvariantCulture);
                if (myDate > DateTime.Today)
                {
                    Console.WriteLine("greater than");
                }
               else
                {
                 Console.WriteLine("Less Than");
                }
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 :: C# api get value from header 
Csharp :: instantiate prefab unity 
Csharp :: c# show list in richtextbox 
Csharp :: unity input system 
Csharp :: sequelize top 
Csharp :: c# datagridview double click on cell 
Csharp :: return an interface or a class C# 
Csharp :: compare two strings in c# 
Csharp :: c# remove time in datetime 
Csharp :: c# datetime remove days 
Csharp :: listview imagelist c# 
Csharp :: c# increment by 1 
Csharp :: unity singleton 
Csharp :: unity get max occurrence in list 
Csharp :: c# creating an array 
Csharp :: password regex asp.net 
Csharp :: adding to a dictionary unity 
Csharp :: c# generic return type in interface 
Csharp :: c# array.reduce 
Csharp :: serenity frameword order column 
Csharp :: c# convertir caracter con tilde 
Csharp :: getelement video 
Csharp :: linq c# object except two lists 
Csharp :: instantiate type c# 
Csharp :: linq select max value from list 
Csharp :: adding additional parameter to form submit 
Csharp :: c# try parse date yyyymmdd 
Csharp :: c# if statement no braces 
Csharp :: c# how to get a file path from user 
Csharp :: 2d array rows and columns in c# 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =