How do I add times to a date with SQL?


Yes, that’s right.

However, apart from the ones we discussed a while agoVertica and MySQL also offer a few more ways on which you can fall back if you’d like to have simpler syntax.

These are:

DB Function Comment
Vertica add_months(timestamp, unit) adds months to a date
MySQL adddate(timestamp, unit) adds days to a date
MySQL addtime(timestamp, unit) adds seconds to a date
MySQL subdate(timestamp, unit) subtracts days from a date
MySQL subtime(timestamp, unit) subtracts seconds from a date
MySQL period_add(yyyymm, unit) adds months to a year-month period*

*super handy if used with dynamic year-month periods and you can easily get those by using the concat() function

Happy SQL-ing!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.