如何获得前一个monnth的最后一天 [英] How to get the last day of previous monnth

查看:80
本文介绍了如何获得前一个monnth的最后一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得上个月的最后一天?前两个月的最后一天?

表示当我给getdate()我需要feb lastday和january lastday ..



< b>我尝试了什么:



我试过但是我不确定如何得到它。

How to get the last day of previous month?? and last day of prior two months?
means when i give getdate() i need feb lastday and january lastday also..

What I have tried:

I tried but iam not sure how to get it.

推荐答案

你好,

参考链接:
Hello,
Refer link :
SQL SERVER – Find Last Day of Any Month – Current Previous Next







简短




In Short

----Last Day of Month before Previous Month 
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())-1,0))

 
----Last Day of Previous Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0))

----Last Day of Current Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))

----Last Day of Next Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+2,0))


select DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1)


这篇关于如何获得前一个monnth的最后一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆