How can I get the end date of a quarter with SQL?

It will depend on the database you're using! As you can see below, there can be quite some variations in syntax between Vertica, SQL Server, MySQL, PostgreSQL   So, what's common in all these examples? In all cases, you will need: a function that gets the current date a function that extracts the year from … Continue reading How can I get the end date of a quarter with SQL?

How do I extract part of a date with SQL? (2)

Yesterday, we looked at the standard approach of aggregating daily data stretching over a longer time periods If you're lucky enough to be working with Vertica or MySQL, you can also rely on functions like: year(), quarter(), month(), week(), day() SQL Server also supports some of them - year(), month(), day() - but is by far the most limited of … Continue reading How do I extract part of a date with SQL? (2)

How do I convert a timestamp to another timezone with SQL?

Have you ever had that request? I would like to have the distribution of clicks per hour for the last week in local time It's a no brainer if your database server is in the same time zone as your business audience  - then you just need to aggreate the clicks' timestamps to an hour. Not … Continue reading How do I convert a timestamp to another timezone with SQL?

How do I add times to a date with SQL?

  Yes, that's right. However, apart from the ones we discussed a while ago,  Vertica 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 … Continue reading How do I add times to a date with SQL?

How do I find the date that is a number of months from/before now with SQL?

Did you ever have to check what the status of an indicator was exactly: 2 years ago 6 months ago 3 weeks ago What is crucial in each one of those instances is the ability to calculate what the exact date at the time was, so that you're retrieving data for corresponding periods. It can … Continue reading How do I find the date that is a number of months from/before now with SQL?