1
0

More than 3 years have passed since last update.

MySQLの「0000-00-00 00:00:00」のdatetime型をCarbonオブジェクトで判別する

Last updated at Posted at 2019-11-05

MySQLのDatetime型で、うかうかしていると「0000-00-00 00:00:00」というデータが格納され、
Carbonでそのデータを引っ張ると「-0001-11-30」という不思議な日付が返ってくることに悩まされました。

試行錯誤してみて、

echo $thatTime->year;//-1

という値が返ってくるのがわかったので、

if($thatTime->year === -1)

という判別式で除外できるな、と。

紀元前を扱うことのないシステムであれば、これで十分そうです。

小ネタですが、同じ課題に時間を取られる人への一助となれば。

1
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
1
0