如何获得一个月的第一个和最后一个日期 [英] How to get the First and Last date of a month

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

问题描述

大家好

我想查找一个月的第一个和最后一个日期.谁能帮我解决这个问题.我有一个充满月份的组合框,即一月,二月,三月...等.现在我想要的是我将从组合框中选择月份",那么我应该获得该月的第一个和最后一个日期.有人可以帮我吗?



预先感谢

Jagdish

Hello everyone,

I want to find the first and last date of a month. can anyone help me out how to get it. I have a combobox filled with months i.e. January, February,March,...... and so on. Now what i want is i will select the Month from the combobox, then i should get the first and last date of that month. Can any one help me out in doing so.



Thanks in Advance

Jagdish

推荐答案

我发现 [ ^ ]在
I found this[^] in 1st page of Google[^]. Always hit in search engine before asking here because it''s frequent & easy one, You can find this by searching in CP.


很显然,该月的第一天是 1 :rolleyes:

可以从
Calendar.GetDaysInMonth [
Well quite obviously the first day of the month is 1 :rolleyes:

The last day can be obtained from Calendar.GetDaysInMonth[^]


Private Function GetFirstDateOfMonth(ByVal iMonth As Integer)<br />
        Dim dtFrom As DateTime = New DateTime(DateTime.Now.Year, iMonth, 1)<br />
        dtFrom = dtFrom.AddDays(-(dtFrom.Day - 1))<br />
        Return dtFrom<br />
    End Function<br />
<br />
    Private Function GetLastDateOfMonth(ByVal iMonth As Integer)<br />
        Dim dtTo As New DateTime(DateTime.Now.Year, iMonth, 1)<br />
        dtTo = dtTo.AddMonths(1)<br />
        dtTo = dtTo.AddDays(-(dtTo.Day))<br />
        Return dtTo<br />
    End Function




我找到了查询的答案,因此想到了将其发布在这里.我们可以从这些函数中获取一个月的第一个和最后一个日期.




I found the answer for my query so thought of posting it here. we can get the first and last date of a month from these functions.


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

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