The database has 3 fields with dates. This means 3 segments. To x1, from x1 to x2, from x2 to x2 + x days. And the segment of the chart itself is usually 24 hours, i.e. y1 and y1 + 23:59:59, where y1, for example, 03/10/12. I work with time in Unix format, i.e. seconds.

The complexity itself is to deduce from the database the fields that fall within the conditions of this chart. For example:

10.03.12 00:00|---------------------------------------------|10.03.12 23:59:59

And in the database

05.03.12 10:00, 10.03.12 12:00, 10.03.12 11:00

i.e our time span falls into range. The central date does not take sense, but only the extreme parts of the range.

How to set the withdrawal condition? There is actually a couple of comparisons, but it is necessary that even if 1 hour falls, then output. Or half-band, for example:

10.03.12 00:00|---------------------------------------------|10.03.12 23:59:59

And in the database

10.03.12 23:00, 12.03.12 12:00, 15.03.12 11:00

those. The first date for the hour, but falls into our schedule.

PS The beginning and end of the segment should also be taken into account, because the schedule can be either a day or a week, and you will have to output data that at least falls into the graph, for example:

10.03.12 00:00|---------------------------------------------|17.03.12 23:59:59

And in the database

11.03.12 10:00, 12.03.12 12:00, 13.03.12 11:00

They were completely hit, but only an hour of the schedule at the beginning or an hour at the end could.

The function of drawing graphics colors is and displays in increments of an hour.

  • You can correlate xN with the corresponding fields, explain how equal x is. then, perhaps, they will help you soon - AseN

1 answer 1

I do not know what you have there for the database, but in mysql there is such a thing as an interval, you can easily use it to work with the date, such as

 SELECT INTERVAL 1 DAY + "1997-12-31"; 

or if you just count on the numbers, you can

 SELECT id FROM table WHERE id > 1 AND id < 5 
  • > I do not know what you have there for the database, but in mysql there is such a thing as an interval, for> working with the date, you can easily use it, such as it is more convenient for me to work with Unix time, because the script itself is still translating time zones, etc. e> or if you can just count on the numbers, you can do it. So, I just need a formula (as you showed, it doesn’t work because I use 4 times (2 segments start and end them). As you showed, I tried in different ways , but there are a lot of moments when intervals fall out. On paper, it was modeled with prime numbers (Heads Pete. That's why he asked for help - lnart