how is the date value formated in php

Viewed 20

I'm new to php and trying to learn it. I created a database and one of my fields has the date value. I have tried many times to insert a date and keep getting errors. I need to figure out how to format a date. I have song table and inside the song is a year field that will display the year the song came out. my code is below as well as the error

DB::table('users')->delete();
    User::create(array(
        'name'     => 'Appetite for destruction',
        'Year' => '1987-11-11',
        
        
    ));

The error is below

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Year' in 'field list' (SQL: insert into users (name, Year, updated_at, created_at) values (Appetite for destruction, 1987-11-11, 2021-11-14 22:47:58, 2021-11-14 22:47:58))

[PDOException] SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Year' in 'field list'

db:seed [--class [CLASS]] [--database [DATABASE]] [--force]

1 Answers

Review this: PHP: DateTime::format

You can formate dates in PHP like this:

$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:s'); // OUTPUT: 2000-01-01 00:00:00
Related