Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.
以下の例で使用する変数
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
CodeOne
【品質と生産性にこだわるシステム開発】 .NET(C#/VB.NET)専門・リモート開発歴10年。即日・1時間から頼める常駐しないエンジニア。確かな技術で開発チームを手堅くサポートします。
https://codeone.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした