Arthur Fuzaro Arthur Fuzaro - 11 months ago 55
C# Question

Compare DateTime.Now with a custom Date

I want to know how I Should compare with my custom time, for example I want to know if the current time is in the middle of


It's Simple, but I not getting how should I Compare this times.

Thanks a lot

Answer Source

You can do by this

DateTime now = DateTime.Now;
DateTime d1 = DateTime.ParseExact(now.ToString("dd/MM/yyyy")+ " 09:00", "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture);

if (now > d1)