ssCAROのブログ

色んなとこで見つけたプログラムのメモ置き場っぽい

VB.NETで月の末日を取得する

指定した月に1か月足して1日引いて・・・と求めていたけどDaysInMonth()で取得できる。

Dim temp As DateTime = DateTime.Now()
Debug.Print(DateTime.DaysInMonth(temp.Year, temp.Month))

'末日を返すサンプル
Public Function LastDay(d As DateTime) As DateTime
    Return DateTime.Parse(String.Format("{0:0000}/{1:00}/{2:00}", d.Year, d.Month, DateTime.DaysInMonth(d.Year, d.Month)))
End Function