Skip to main content
awhitter
Gold ⭐️
Jun 11, 2017 4:48 PM UTC

How do you add minutes / days / months to a date in phoenix?

  • Oct 5, 2026 9:22 AM UTC
  • 0 replies
  • 4999 views
  • Translate All

Question: Are there any functions which allow date arithmetic with phoenix?

Answer: this is done as a fraction of a day. e.g. to add 12 hours to a day:

> select now(), now() + (0.5) ;
+---------------------------------+---------------------------------+
| DATE '2017-06-04 16:55:07.989' | DATE '2017-06-05 04:55:07.989' |
+---------------------------------+---------------------------------+
| 2017-06-04 16:55:07.989 | 2017-06-05 04:55:07.989 |
+---------------------------------+---------------------------------+

To add 15 minutes you would use (15/1440). ie.

0: jdbc:phoenix:> select now(), now() + (0.010416666666667) ;
+---------------------------------+---------------------------------+
| DATE '2017-06-04 16:56:31.492' | DATE '2017-06-04 17:11:31.492' |
+---------------------------------+---------------------------------+
| 2017-06-04 16:56:31.492 | 2017-06-04 17:11:31.492 |
+---------------------------------+---------------------------------+
1 row selected (0.024 seconds)

See also: RMP-9148 "Provide Date arithmetic functions for Phoenix"