V
V
Victoria Smirnova2017-08-01 13:24:41
MySQL
Victoria Smirnova, 2017-08-01 13:24:41

Calendar in Mysql DB?

Is it possible to create a table with dates and times, for example:
from 01.00 01.01.2017
02.00 01.01.2017
....
to 24.00 12.31.2017
or will you have to type everything manually?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2017-08-01
@Rsa97

Can.

For example, like this:
SELECT '2017-01-01' + INTERVAL `d`.`dayOfYear` DAY + INTERVAL `h`.`hour` HOUR
  FROM (
    SELECT (`c`.`num`*100+`d`.`num`*10+`s`.`num`) AS `dayOfYear`
      FROM (
        SELECT 0 AS `num`
        UNION SELECT 1
        UNION SELECT 2
        UNION SELECT 3
        UNION SELECT 4
        UNION SELECT 5
        UNION SELECT 6
        UNION SELECT 7
        UNION SELECT 8
        UNION SELECT 9
    ) AS `s`
    JOIN (
      SELECT 0 AS `num`
        UNION SELECT 1
        UNION SELECT 2
        UNION SELECT 3
        UNION SELECT 4
        UNION SELECT 5
        UNION SELECT 6
        UNION SELECT 7
        UNION SELECT 8
        UNION SELECT 9
      ) AS `d` ON TRUE
      JOIN (
        SELECT 0 AS `num`
        UNION SELECT 1
        UNION SELECT 2
        UNION SELECT 3
        UNION SELECT 4
        UNION SELECT 5
        UNION SELECT 6
        UNION SELECT 7
        UNION SELECT 8
        UNION SELECT 9
      ) AS `c` ON TRUE
      HAVING `dayOfYear` < DAYOFYEAR('2017-12-31') 
  ) AS `d`
  JOIN (
    SELECT 0 AS `hour`
    UNION SELECT 1
    UNION SELECT 2
    UNION SELECT 3
    UNION SELECT 4
    UNION SELECT 5
    UNION SELECT 6
    UNION SELECT 7
    UNION SELECT 8
    UNION SELECT 9
    UNION SELECT 10
    UNION SELECT 11
    UNION SELECT 12
    UNION SELECT 13
    UNION SELECT 14
    UNION SELECT 15
    UNION SELECT 16
    UNION SELECT 17
    UNION SELECT 18
    UNION SELECT 19
    UNION SELECT 20
    UNION SELECT 21
    UNION SELECT 22
    UNION SELECT 23
  ) AS `h` ON TRUE

A
aol-nnov, 2017-08-01
@aol-nnov

Yes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question