SQL Query to get dates of X days after current date

S_S

How can i construct a query that would return some 'x' number of dates after the current date (sysdate)?

For example if today is 18-May-2018 and I ask for x=2, then I should get

19-May-2018

20-May-2018

as the output.

Kaushik Nayak

You may use generate_series.

SELECT generate_series(current_date + 1, 
                       current_date + 2, 
                       interval '1' day)

Docs

In plsql, you may set x as variable and then use it in your query.

knayak=# \set x 5
knayak=# SELECT generate_series(current_date + 1,                                                                                                            
                                current_date + :x,                                                                                                                        
                                interval '1' day);

 generate_series      
---------------------------
 2018-05-19 00:00:00+05:30
 2018-05-20 00:00:00+05:30
 2018-05-21 00:00:00+05:30
 2018-05-22 00:00:00+05:30
 2018-05-23 00:00:00+05:30

You may format the dates in desired format with TO_CHAR

SELECT  to_char(dt,'DD-MON-YYYY') as dates
FROM    generate_series(current_date + 1, 
                        current_date + 2, 
                        interval '1' day) as dt

dates    
-------------
19-MAY-2018
20-MAY-2018

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

SQL Query Current Date Minus 180 days?

Get Dates based on Current Date and List of Week Days

How to get daily count with date generate 2 - 2 days after in last 7 dates in sql server?

SQL Query to display dates weekly from current date

Get array of dates for hours, days, weeks, months between current date/time and end date/time

Sql Query to get Data based on Current Date

SQL Query: Return value starting 28 days from parameter date to 56 days after parameter date

SQL query get business days from two date columns

Sum 7 days after current date in Django

SQL query to get a list of date ranges by month between two dates

How to get next dates after selecting a single date with a gap of 7 days

PURE SQL get days beteen given date and current date, without functions

Current Date converted to 10 days before and 10 days after

Get past weeks days date of current month

How to get 30 days prior to current date?

Get date value of every days of current month

Get a Query that can display of 30 days based on table data and not current date

How to disable the dates after current date?

SQL Server query to get the number of business days between 2 dates, excluding holidays

Selecting a record because its date field is X days after another records date field SQL

Get dates between date of ID and date of plus or minus days

Displaying dates values for current date in SQL Server

Comparing dates with current date in Sql server

SQL query for removing current and future dates?

sql query to add days to specific column date

SQL date query show non existing days

Subset dataframe where date is within x days of a vector of dates in R

Dynamic SQL query which calculates the revenue generated for first X days since the onboarded Date

How to get date after subtracting days in pandas