简体   繁体   中英

How to get start and end dates of current month

How to get start date and end dates in a query from database.

Thanks,

Lico

http://sqltutorials.blogspot.com/2007/06/sql-first-and-last-day-of-month.html

Only thing that isn't covered is how to retrieve the current date... see rexem's post.

CURRENT_DATE[()] | CURDATE() | SYSDATE | TODAY = returns current date

Start of month:

DATE EXTRACT(YEAR FROM SYSDATE) +'-'+ EXTRACT(MONTH FROM SYSDATE) +'-01'

For completeness, start of month:

DATE EXTRACT(YEAR FROM SYSDATE) +'-'+ EXTRACT(MONTH FROM SYSDATE) +'-01' 

End of month:

DATEADD('DAY', -1, DATEADD('MONTH', 1, DATE EXTRACT(YEAR FROM SYSDATE) +'-'+ EXTRACT(MONTH FROM SYSDATE) +'-01'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM