简体   繁体   English

如何获得本月的开始和结束日期

[英]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 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. 唯一没有涉及的是如何获取当前日期...请参阅rexem的帖子。

CURRENT_DATE[()] | CURRENT_DATE [()] | CURDATE() | CURDATE()| SYSDATE | SYSDATE | TODAY = returns current date TODAY =返回当前日期

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'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在SSRS报表中获取当月的开始和结束日期 - How to get Current Month's Starting and End dates in SSRS report 动态声明当前月份的开始/结束日期 - Dynamically Declare Start/End Dates From Current Month 获取具有不同月份开始和结束日期的月份名称 - Get month name with different month start and end dates 在SQL中的两个日期之间获取月份的开始和结束日期? - Get start and end dates of month in between two dates in SQL? 如何使用SQL获取每年的每月BiWeekly日期以及星期ID,开始日期和结束日期? - How to get BiWeekly Dates per month in year with week id, start and end date using SQL? 如何为上一年和当年指定 4 个不同的开始和结束日期,都使用 SET 指定当月的第一天? - How can I specify 4 different start and end dates for previous year and current year all specifying the 1st day of the month using SET? SQL - 获取当前日期与一周开始和结束之间的所有日期 - SQL - Get all dates between Current day and start and end of week 如何获得周开始和结束日期? - How to get the week start and end dates? 获取当前周/月日期 - Get Current Week/Month Dates 有没有办法在 SQL 中设置过去 4 个完整月份和当前月份的相对开始和结束日期? - Is there a way to set relative start and end dates in SQL for last 4 complete months and current month to date?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM