Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

sql - Months between 2 dates | postgreSQL

I have 2 dates 1-Jan-18 , 1-Apr-18 and I want that by giving start and end date function returns all the month like:

jan 18
Feb 18
Mar-18
Apr-18

all the month list that lies in between the date.

question from:https://stackoverflow.com/questions/65679899/months-between-2-dates-postgresql

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use generate_series but it will fail if your dates are not on the same date - e.g. if the start date is 2017-10-30 and the end date is 2018-02-28

SELECT generate_series('2018-01-01','2018-04-01',interval '1 month');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...