第一天和最后一个月 [英] fist day and last in a month

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

问题描述

如何找到给定月份的第一天和最后一天,,,



ex:我将进入三月份,以获取行军的第一天1- 3-2014,最后一天31-3-2014



回复

how to find first day and last day in given month,,,

ex: i will enter march month , to get the first day of march 1-3-2014 , last day 31-3-2014

reply

推荐答案

您好,
谷歌有很多例子。首先从这个链接看到DateTime结构

日期时间结构

然后试试这个

Hello,
there are many examples available in google.First see the DateTime structure from this link
DateTime Structure.
Then Try this
var today = DateTime.Today;
var month = new DateTime(today.Year, month , 1); //Put month as 3 if it is March      
var firstday = month.AddMonths(-1);
var lastday = month.AddDays(-1);



谢谢


thanks


Firstday:

Firstday:
DateTime FD= new DateTime(2014, 3, 1);



LastDay:


LastDay:

DateTime LD= FD.AddMonths(1).AddDays(-1);


chk thi link:



http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/ [ ^ ]





chk thi link :

http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/[^]


DECLARE @mydate DATETIME
SELECT @mydate = GETDATE()
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@mydate)),@mydate),101) ,
'Last Day of Previous Month'
UNION
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@mydate)-1),@mydate),101) AS Date_Value,
'First Day of Current Month' AS Date_Type
UNION
SELECT CONVERT(VARCHAR(25),@mydate,101) AS Date_Value, 'Today' AS Date_Type
UNION
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))),DATEADD(mm,1,@mydate)),101) ,
'Last Day of Current Month'
UNION
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))-1),DATEADD(mm,1,@mydate)),101) ,
'First Day of Next Month'


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

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