Pages

Thursday, 26 March 2020

Compare date in dd/mm/yyyy format C#



Some programmer needs to compare date in the format of dd/mm/yyyy. C# sharp has reach features of handling date but too complicated. So I made this post which helps you to compare date in dd/mm/yyyy format in simple way.

using System.Globalization;

string strFromDate =  "16/03/2020";
           
string strToDate = "20/03/2020";


DateTime FromDate = DateTime.ParseExact(strFromDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            DateTime ToDate = DateTime.ParseExact(strToDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);

            int result = DateTime.Compare(FromDate, ToDate);

            if (result < 0)
            {
                return RedirectToAction("pdf", new { pdate = date.ToString() });

            }

No comments:

Post a Comment