user1865039
user1865039

Reputation: 131

How to efficiently store schedular dates?

For example I have:

  1. Start date (1 Column)
  2. End date (1 Column)
  3. Weekday: mon, tues, wed, thur, fri, sat, sun (1 Column)

How do I define the week so I can store the above data in a 3 field in the database?

Upvotes: 0

Views: 69

Answers (1)

Kent Pawar
Kent Pawar

Reputation: 2616

From a processing perceptive, storing those 3 fields in a single cell is not recommended. You would have to go through unnecessary overhead to encode and decode the data while writing to and reading from the table and also would need to perform additional data-type conversions!

You could try something like : ,, Where : 124 for Monday, Tuesday and Thursday. But as discussed above, it is not the right way to go about it..

Ideally you have 3 columns for each item and store the weekdays in a number of formats:

  1. <weekday_list_to_run_the _scheduled_tasks>: Where we encode Monday, Tuesday and Thursday as 124. Requires the most processing.
  2. Good-old AND-ing:
    Say we store <weekday_list_to_run_the _scheduled_tasks> = Monday-X-X-Thursday-Fri-X-Sunday as 1001101. Then through 7 AND-ing operations we find the days on which the schedule should run.

Eg.

IF (<weekday_list_to_run_the _scheduled_tasks> AND 1000000) == 1 THEN 
     //Monday is set. 
END IF

Upvotes: 1

Related Questions