9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[.NET] 日付計算いろいろ

Posted at
以下の例で使用する変数
DateTime date = DateTime.Today;

▼前月初日

new DateTime(date.Year, date.Month, 1).AddMonths(-1)

▼前月同日

date.AddMonths(-1)

▼前月末日

new DateTime(date.Year, date.Month, 1).AddDays(-1)

▼前々月末日

new DateTime(date.Year, date.Month, 1).AddMonths(-1).AddDays(-1)

▼当月初日

new DateTime(date.Year, date.Month, 1)

▼当月末日

new DateTime(date.Year, date.Month, DateTime.DaysInMonth(date.Year, date.Month))

▼翌月初日

new DateTime(date.Year, date.Month, 1).AddMonths(1)

▼翌月末日

new DateTime(date.Year, date.Month, 1).AddMonths(2).AddDays(-1)

▼1年前の前月初日

new DateTime(date.Year, date.Month, 1).AddYears(-1).AddMonths(-1)

▼1年前の前月末日

new DateTime(date.Year, date.Month, 1).AddYears(-1).AddDays(-1)

▼1年前の当月初日

new DateTime(date.Year, date.Month, 1).AddYears(-1)

▼4月開始年度

date.AddMonths(-3).Year
9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?