On my attachment have the table

I want to know how to make the comparison like:

DUE_DATE_TIME + DURATION(in hours) <= OVER_DUE_DATE_TIME

If the above statement is wrong then must prompt out the message box:
(I'm also need help in how to prompt out the message box, Thanks)

Can yours show the code in C#.net


Pleaseeee helpppp , thanks in advance

Dani AI

Generated

A simple, reliable approach is: parse the two dates, add the duration (hours) to the due date, then compare the result to the over‑due date. Handle DBNull/parse failures and time zones up front so the comparison is deterministic. As hinted, use DateTime; and as noted, pick the MessageBox overload you need.

using System;
using System.Data;
using System.Windows.Forms;

foreach (DataRow row in myTable.Rows)
{
    if (row.IsNull("DUE_DATE_TIME") || row.IsNull("OVER_DUE_DATE_TIME"))
        continue;

    DateTime due;
    DateTime over;
    double hours;

    if (!DateTime.TryParse(row["DUE_DATE_TIME"].ToString(), out due)
        || !DateTime.TryParse(row["OVER_DUE_DATE_TIME"].ToString(), out over)
        || !double.TryParse(row["DURATION"].ToString(), out hours))
    {
        MessageBox.Show("Invalid date/duration in row.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        continue;
    }

    DateTime duePlus = due.AddHours(hours); // supports fractional hours
    if (duePlus <= over)
        MessageBox.Show("OK: due + duration is <= over due.", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information);
    else
        MessageBox.Show("Violation: due + duration > over due.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}

Notes and troubleshooting

  • If DURATION is stored as minutes/seconds or as a TimeSpan, use TimeSpan.FromHours(...) or add the TimeSpan directly.
  • If values may come from different time zones, convert both DateTime values to UTC (.ToUniversalTime()) before comparing.
  • Use TryParseExact with a known format when dates come as strings to avoid culture issues.
  • For large datasets validate the logic in SQL (e.g., DATEADD(hour, duration, due_date_time) <= over_due_date_time) to reduce round trips.

Recommended Answers

All 2 Replies

I won't write code for you but I'll guide you to the class which helps you in such problem TimeStamp and for message box, MessageBox.Show("Message...");

there are 12 types of messagebox...:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.