0
0

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.

DATETIME型の年月日時刻の一部分を切り取って表示するには

Last updated at Posted at 2020-12-19

DATETIME型の必要な部分だけ切り取る方法

DATETIME型は「2020-12-01 00:00:00」のように年から秒までの日付と時刻が格納されています。
これを「2020-12-01」や「00:00:00」のように部分的に切り取って表示したい場合にsubstr関数が使えます。

index.php
<?php
$date = "2020-12-01 00:00:00";

// 「年-月-日」
$date1 = substr($date,0,10);

// 「月-日」
$date2 = substr($date,5,5);

// 「時刻」
$date3 = substr($date,11,8);

?>
substr(対象のデータ, 切り取る開始位置, 切り取る数)
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?