Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3952958
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:55:01+00:00 2026-05-20T01:55:01+00:00

I have a todo list in the database. Each Item has a todo item

  • 0

I have a todo list in the database. Each Item has a todo item with a time by which it should be completed. What I want to do is have my C# application loop through the items and check if the item should’ve been completed an hour ago, at tops. Also the application must check if the item should be complete within the hour. If any of these two options is true, the job has to be shown to the user.

How can I make this work? I thought of the way below, but that will show any item that should’ve been completed an hour ago, or more. I want the items that should’ve been completed already, with an maximum of 1 hour ago.

foreach (DataRow dr in dsValue.Tables[0].Rows)
{
    DateTime dt = Convert.ToDateTime(dr["tijd"]);

    if (dt > DateTime.Now.AddHours(-1) || dt < DateTime.Now.AddHours(1))
    {
        MessageBox.Show(dr["opdracht"].ToString());
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T01:55:01+00:00Added an answer on May 20, 2026 at 1:55 am

    Your code would almost work — you want both conditions to be true, not either, so a quick change to:

    foreach (DataRow dr in dsValue.Tables[0].Rows)
    {
        DateTime dt = Convert.ToDateTime(dr["tijd"]);
    
        if (dt > DateTime.Now.AddHours(-1) && dt < DateTime.Now.AddHours(1))
        {
            MessageBox.Show(dr["opdracht"].ToString());
        }
    }
    

    …would suffice. It may be (much) more efficient to move the logic to the database, or at the very least precalculate “an hour ago” and “an hour’s time” outside of the loop.

    For example, if your SQL looked a s little like

    DECLARE @HourAgo DATETIME
    SET @HourAgo = DATEADD(HOUR,-1,GETDATE())
    DECLARE @HoursTime DATETIME
    SET @HoursTime = DATEADD(HOUR,1,GETDATE())
    SELECT
        opdracht,
        [other columns]
    FROM ExampleTable
    WHERE
        opdracht BETWEEN @HourAgo AND @HoursTime
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of pages collected from my database. Each page has an
Have/Want List Matching Algorithm I am implementing an item trading system on a high-traffic
I am trying to get a List<EntityType> , each item has about 15 navigation
I have a list of values that I am looping through, determining whether each
I have a php for each loop which outputs a form for every product
I get user list from database in jsp. In each user I have a
I have a listview and each item has a title, some info, and a
I have resharper installed and I use the todo list functionality pretty often. My
So I have xml that looks like this: <todo-list> <id type=integer>#{id}</id> <name>#{name}</name> <description>#{description}</description> <project-id
I have code which needs to do something like this There is a list

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.