t27duck / active_reporting

OLAP-like DSL for ActiveRecord-based reporting
MIT License
136 stars 19 forks source link

add date option to datetime drill #35

Closed germanotm closed 4 years ago

germanotm commented 4 years ago

Needed a way to select the full date with year-month-day from a datetime column, therefore, I added a date option to DATETIME_HIERARCHIES array.

On mysql there is a DATE() function to do that:

mysql> select DATE("2010-02-05 3:00:00");
+----------------------------+
| DATE("2010-02-05 3:00:00") |
+----------------------------+
| 2010-02-05                 |
+----------------------------+

In order to also support this on postgres, I used postgres DATE() function, because there is no such option on date_trunc

postgres=# SELECT DATE(TIMESTAMP '2020-02-05 3:00:00');
    date    
------------
 2020-02-05