string minute = "15";
        string minute2 = "20";
        string minute3 = "27";
        string minute4 = "02";
        TimeSpan first = TimeSpan.Parse(minute);
        TimeSpan second = TimeSpan.Parse(minute2);
        TimeSpan Third = TimeSpan.Parse(minute3);
        TimeSpan fourth = TimeSpan.Parse(minute4);
        TimeSpan now = DateTime.Now.TimeOfDay;

        if (now == first|| now == second || now == Third || now == fourth)
        {
            //matched
        }
        else
        {

        }
    }

      is it correct what i have done in asp.net   because i am not geeting proper output

Dani AI

Generated

In ’s snippet the code parses minute strings to TimeSpan and compares those to DateTime.Now.TimeOfDay. DateTime.Now.TimeOfDay contains hours, minutes, seconds and fractions, so a strict equality test succeeds only when hour, minute, second and millisecond all line up — that is why the check often appears to “not work.”

A simple, robust approach when the intent is “this minute-of-hour equals one of these values” is to compare the integer minute component:

using System.Linq;

var targetMinutes = new[] { 15, 20, 27, 2 };
if (targetMinutes.Contains(DateTime.Now.Minute))
{
    // matched
}

If the goal is to fire at a specific time-of-day (hour and minute), compare hour and minute, or build TimeSpan values that include hours and minutes:

var now = DateTime.Now;
if ((now.Hour == 10 && now.Minute == 15) || (now.Hour == 14 && now.Minute == 20))
{
    // matched at those hh:mm
}

Troubleshooting notes and cautions: prefer TryParse/TryParseExact or int.TryParse when converting strings to avoid exceptions; log DateTime.Now in full (e.g. ToString("HH:mm:ss.fff")) to see what’s actually compared; remember ASP.NET code runs on the server (DateTime.Now is server local time) — client-local checks need client-side JavaScript; and a page-based check only runs when the page executes, so schedule a background job or timer if a precise minute trigger is required. As hinted, clarifying whether the intent is “match minute-of-hour” or “run at exact hh:mm:ss” will determine which of the above patterns is appropriate.

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.