Everyday SQL (8) SQL- Date shift by day, week, month, quarter, or year

Add days, weeks, month, quarter, year to a date: use positive number

#minus days, weeks, month, quarter, year from a date: use negative number

Example

# minus 1 week from January 18th, 2019 :

processed_date >= dateadd(week, -1, ‘20190118’)

#or

processed_date >= dateadd(weeks, -1, ‘20190118’)

#week and weeks are the same for dateadd function.

#you can change weeks to day, week, year, month, or quarter

Be the first to comment

Leave a Reply

Your email address will not be published.


*