Note that there are some explanatory texts on larger screens.

plurals
  1. POTimespan - Check for weekday and time of day in mysql
    primarykey
    data
    text
    <p>I need to have a database with different rates at different time of day and on different weekdays.</p> <p>For example: <code>Between 10:00 and 16:00 monday to friday I have one rate. Between 16:00 and 10:00 monday to friday I have another. And on the weekends there is another rate.</code></p> <p>The problem is when the time goes over midnight.</p> <p>I have looked around for a solution. I have found this thread that I thought would work for me but it doesn't. At least I can't get it to work as I want it to. <a href="https://stackoverflow.com/questions/8278521/dealing-with-times-and-after-midnight/">Dealing with times and after midnight</a></p> <p>The other solution I tried didn't work either. It was to store time as TIME in mysql and check if the time and day was between the timespan in the database. This didn't work out either because I didn't find a good solution for when the timespan goes over midnight.</p> <p>How should I try to solve this? What should the database look like and the query to get the data?</p> <p>Edit:</p> <p>Here is what it got so far. <code>starttid</code> = start time, <code>sluttid</code> = end time. <code>Ovrig_tid</code> is used when it's not any of the specific times. <code>startdag</code> = start day of week, <code>slutdag</code> = end day of week. 0 = monday, 6 = sunday. So the result should be max one from every <code>bolag_id</code>. </p> <p><a href="http://desmond.imageshack.us/Himg829/scaled.php?server=829&amp;filename=example1tm.jpg&amp;res=medium" rel="nofollow noreferrer">http://desmond.imageshack.us/Himg829/scaled.php?server=829&amp;filename=example1tm.jpg&amp;res=medium</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload