I have a table which has a DATE
-column, along with a int
modifier column. I'd like to somehow be able to add x
days to the DATE
-column, where x
is the modifier's value.
Something like this:
SELECT t.dateField, DATE_ADD(t.dateField, t.dateModifierValue)
FROM fooTable t
However, that is obviously an invalid SQL-query. Here is what I am trying to achieve:
+------------+-----------+-----------------+
| DateField | Modifier | Expected result |
+------------+-----------+-----------------+
| 2013-05-11 | 7 | 2013-05-18 |
| 2013-01-01 | 1 | 2013-01-02 |
+------------+-----------+-----------------+
Sure, this could be done using multiple queries, letting another language build up the query — but where would the fun be in that?
SELECT t.dateField, DATE_ADD(t.dateField, INTERVAL t.dateModifierValue DAY) FROM fooTable t;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With