How to Get the Previous Month in SQL Database: Standard SQL Oracle MS SQL Server MySQL PostgreSQL Operators: EXTRACT() CURRENT_TIMESTAMP INTERVAL Table of Contents Problem Solution Discussion Problem You would like to display the previous month (without time information) in a database. Solution For PostgreSQL and MySQL: SELECT EXTRACT(MONTH FROM CURRENT_TIMESTAMP - INTERVAL '1' MONTH) AS previous_month; For Oracle: SELECT EXTRACT(MONTH FROM CURRENT_TIMESTAMP - INTERVAL '1' MONTH) AS previous_month FROM dual; Assuming today is March 4, 2020, the result is: previous_month 2 Discussion To get the previous month, subtract one month from today's date. Use CURRENT_TIMESTAMP to get today's date. Then, subtract 1 month from the current date using INTERVAL '1' MONTH. Finally, extract the month from the date using the EXTRACT() function with the MONTH parameter. Recommended courses: SQL Basics Standard SQL Functions Recommended articles: SQL for Data Analysis Cheat Sheet Performing Calculations on Date- and Time-Related Values Analyze Time Series COVID-19 Data with Window Functions SQL Date and Time Functions in 5 Popular SQL Dialects See also: How to Get Yesterday’s Date in MySQL How to Get Yesterday’s Date in Oracle How to Get Yesterday’s Date in PostgreSQL How to Get the Month from a Date in MySQL How to Add Days to a Date in MySQL Subscribe to our newsletter Join our monthly newsletter to be notified about the latest posts. Email address How Do You Write a SELECT Statement in SQL? What Is a Foreign Key in SQL? Enumerate and Explain All the Basic Elements of an SQL Query