DATE FORMAT COMPARISON ISSUE

marcel ethan

Total Post:105

Points:735
Posted by  marcel ethan
C# 
C#
 895  View(s)
Ratings:
Rate this:

I need to execute an condition where after starting from 150 days from today using the system date format.

String test = DateTime.Now.ToString("dd.MM.yyy");

String test2 =DateTime.Now.AddDays(150).ToString("dd.MM.yyy");

if (test == test2)//Not sure how to do it in IF condition here for date tim

{

}

Any help on this would be great.

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: Date Format Comparison Issue

    Hi Marcel,


    var dateToUse = DateTime.Now; // can be any DateTime value, if you use DateTime.Now the condition is useless

    var date1 = dateToUse.Date; // Get Date part

    var date2 = DateTime.Today.AddDays(150);

    if (date1 == date2)

        ;  // Do something if dates are equal

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!