Note that there are some explanatory texts on larger screens.

plurals
  1. POIncreasing Processing Time
    primarykey
    data
    text
    <p>I have a piece of code which compares and validate dates.</p> <p><strong>Problem:</strong></p> <p>This code is taking too much time during execution. When i comment this code the execution takes much less time. From this i can understand this code has some overhead in it. Please make suggestions to improve efficiency of this code.</p> <pre><code>DateTime regDate; DateTime dob; extractDate(buffer[5], buffer[6], out regDate, out dob); private void extractDate(string date, string rDate, out DateTime regDate, out DateTime dob) { if (date == "") // Date of birth is not given; { regDate = getStandardDate(rDate); // MM/DD/YYYY dob = regDate.AddYears(-18); } else { dob = getStandardDate(date); } if (rDate == "") { dob = getStandardDate(date); regDate = dob.AddYears(18); } else { regDate = getStandardDate(rDate); } } private DateTime getStandardDate(string date) { bool checkDate = isValidDate(date); if (checkDate) { IFormatProvider culture = new System.Globalization.CultureInfo("en-gb", true); DateTime dt; if (karachiDateFormat) { dt = DateTime.Parse(date); } else { dt = DateTime.Parse(date, culture); } return dt.Date; } else { return DateTime.Now.Date; } } private bool isValidDate(string date) { IFormatProvider culture = new System.Globalization.CultureInfo("en-gb", true); DateTime Ttime; if (!karachiDateFormat) { Ttime = DateTime.Parse(date, culture); } else { Ttime = DateTime.Parse(date); } date = string.Empty; date = Ttime.Date.ToShortDateString(); string[] splitDate = date.Split('/'); int day = Int32.Parse(splitDate[1]); int month, year; month = Int32.Parse(splitDate[0]); year = Int32.Parse(splitDate[2]); DateTime time = DateTime.Now; if ((day &gt; 0 &amp;&amp; day &lt; 32) &amp;&amp; (month &gt; 0 &amp;&amp; month &lt;= 12) &amp;&amp; (year &gt; 1950 &amp;&amp; year &lt; time.Year)) { return true; } else { return false; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload