LoginSignup
0
0

More than 1 year has passed since last update.

月末日を取得

Posted at

ORACLEだとそのものズバリの関数があります。

SELECT LAST_DAY(SYSDATE) AS END_OF_MONTH FROM DUAL;

C#だと取り敢えず二通り思い浮かびます。
もっとスマートにコードも少なく記述できる方法がありそうな気もしますが。

DaysInMonthを使う
int this_month_days = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
DateTime endOfMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, this_month_days);
翌月の月初日から1日前を求める
DateTime endOfMonth  = new DateTime(DateTime.Now.AddMonths(1).Year, DateTime.Now.AddMonths(1).Month, 1).AddDays(-1);
0
0
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
0
0