こんにちは、スズキです。 Laravelを利用している際に、DBから取得した日付型のデータに対し、「YYYY年MM月DD日」形式のような任意の形式の文字列に変換したい場合ってありますよね? 今回はこの方法を紹介します。 例えば、DBテーブルtest_tablesがあり、test_tables上にpublic_dateというDateTime型のフィールドがあったとします。 この場合、せっかくDateTime型のフィールドを参照しているわけですから、できれば以下のようにPHPのDateTime->formatメソッドを直接呼び出せたらいいなって思いますよね? $targetId = 1; $targetRow = TestTable::query() ->where('id', '=', $targetId) ->first(); $publicDate = $targetRow->publi