0
0

More than 1 year has passed since last update.

PHP - とある月の月末の日付を取得する

Last updated at Posted at 2022-07-15

少々まわりくどいようですが、これが安全な手続きのうちのひとつです。

サンプル

<?php
  // test.php
  $str = '2022-07-16';
  $str = date('Y-m-01', strtotime('1 month', strtotime($str)));
  echo date('Y-m-d', strtotime('-1 day', strtotime($str)));
?>
$ php -f test.php
2022-07-31
$ 
0
0
1

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