validation code snippet : for StateFarmids and Othertimecardids
foreach (var Item in lstTimeCards)
{
DateTime _LastModifiedDateTC = Global.GetTimecardLastModifiedDate(Item.TimeCardID, (int)InvoiceSourceTypes.PerHour ).GetValueOrDefault();
if (Item.LastModifiedDate == _LastModifiedDateTC && IsDateNotMatched == false)

Rajkiran SwainRank #165 · 14.4K reputationPosted Apr 12, 2023, 5:28 AM EDT
string dateStr = "Apr 12 2023 9:21 AM"; // replace with your actual value string format = "MMM d yyyy h:mm tt"; // specify the expected date format DateTime date; if (DateTime.TryParseExact(dateStr, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out date)) { // date is valid, do something } else { // date is invalid, handle error }Naimish MakwanaRank #324 · 7.7K reputationPosted Apr 12, 2023, 11:58 AM EDT
Example code snippet for validating dates in ASP.NET:
// Validate StateFarmids date format (MM/dd/yyyy) if (!DateTime.TryParseExact(txtStateFarmids.Text.Trim(), "MM/dd/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime stateFarmidsDate)) { // Show error message lblStateFarmidsError.Text = "Invalid date format. Please enter a valid date in the format MM/dd/yyyy."; return; } // Validate Othertimecardids date format (dd/MM/yyyy) if (!DateTime.TryParseExact(txtOthertimecardids.Text.Trim(), "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime otherTimeCardIdsDate)) { // Show error message lblOthertimecardidsError.Text = "Invalid date format. Please enter a valid date in the format dd/MM/yyyy."; return; }Thanks