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

  • Home
  • SEARCH
  • 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 8458557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:06:44+00:00 2026-06-10T13:06:44+00:00

I need to run a job/scheduler, which should only update records in database it

  • 0

I need to run a job/scheduler, which should only update records in database it is falling under the specified time range. In my case, the time range is from 3.30 AM to next day 1.30AM. So, with in this time frame the job needs to update the records. In order to get this time interval, I using TimeOfDay() function, but my logic is getting failed, bcoz if the currenttime is say 6.00 Am, then “currentTime <= todaysJob.ENDTIME.Value.TimeOfDay” is returning false. I am using the below code to check

     var currentTime = DateTime.Now.TimeOfDay;
     if (currentTime > todaysJob.STARTTIME.Value.TimeOfDay && 
          currentTime <= todaysJob.ENDTIME.Value.TimeOfDay)
            {
                // Do logic
            }
  • 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-06-10T13:06:46+00:00Added an answer on June 10, 2026 at 1:06 pm
            bool endTomorrow = true;
    
            DateTime taskDate = new DateTime(2012, 08, 31);
    
            TimeSpan Start = new TimeSpan(03, 30, 00);
            TimeSpan End = new TimeSpan(01, 30, 00);
    
            DateTime currentTime = DateTime.Now;
    
            bool flag = false;
    
            if (currentTime.TimeOfDay >= Start)
            {
                if (endTomorrow)
                {
                    flag = currentTime.Date <= taskDate || (currentTime.Date == taskDate.AddDays(1) && currentTime.TimeOfDay < End);
                }
                else
                {
                    flag = currentTime.TimeOfDay < End;
                }
            }
    
            if (flag)
            {
                //do the task
            }
    

    EDIT

    So I added:

    1. a boolean flag, determining whether the task should end the next day
    2. a datetime variable (taskDate) saying the date of the task

    Start and End are equal to todaysJob.STARTTIME and todaysJob.ENDTIME, so you take them from DB as they are.

    EDIT

    If you could have your job like this:

    public class Job
    {
        public TimeSpan STARTTIME;
        public TimeSpan ENDTIME;
        public DayOfWeek taskDayOfWeek;
        public bool IsEndingTommorow;
    
        public bool IsTomorrow(DayOfWeek d)
        {
            if (d == DayOfWeek.Sunday)
                return taskDayOfWeek == DayOfWeek.Saturday;
            else
                return d <= taskDayOfWeek;
        }
    }
    

    then you could

            DateTime currentTime = DateTime.Now;
    
            bool flag = false;
    
            if (currentTime.TimeOfDay >= todaysJob.STARTTIME)
            {
                if (todaysJob.IsEndingTommorow)
                {
                    flag = currentTime.DayOfWeek == todaysJob.taskDayOfWeek || (todaysJob.IsTomorrow(currentTime.DayOfWeek) && currentTime.TimeOfDay < todaysJob.ENDTIME);
                }
                else
                {
                    flag = currentTime.TimeOfDay < todaysJob.ENDTIME;
                }
            }
    
            if (flag)
            {
                //do the task
            }
    

    EDIT

    I’ve edited my code another time: added a method to avoid problems with the DayOfWeek enum

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a job list. Each job has its own run time. They need
I have a rake task I need to run as a daily job on
if i have a php background job, may need to run 4-5hours or more
I need to invoke a mapreduce job from java application. I use ToolRunner.run(new Validation(),
i need run code that will create a database and populate tables. i am
i need to run a job 'x' times a day. job timing is every
I need to run job after another job with whatever status the previous job
In my application I need to have periodically run background tasks (which I can
I need to run a job in a scheduled manner, on tomcat server deployed
I need run ts:reindex when smth add in model or destroy from model. How

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.