PRINT ‘上周的第一天:‘+CONVERT(NVARCHAR(20),DATEADD(WEEK, DATEDIFF(WEEK, 0, GETDATE())-1, 0),120); PRINT ‘本周的第一天:‘+CONVERT(NVARCHAR(20),DATEADD(WEEK, DATEDIFF(WEEK, 0, GETDATE()), 0),120); PRINT ‘上月的第一天:‘+CONVERT(NVARCHAR(20),DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0),120); PRINT ‘本月的第一天:‘+CONVERT(NVARCHAR(20),DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0),120); PRINT ‘上年的第一天:‘+CONVERT(NVARCHAR(20),DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE())-1, 0),120); PRINT ‘本年的第一天:‘+CONVERT(NVARCHAR(20),DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()), 0),120);
How to get first and last day of previous month (with timestamp) in SQL Server
时间: 2024-09-30 19:16:19