Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Sema314's avatar

Protected dates returns negative DateTime on API call

So here is my migration file input where I get all "0000-00-00" by default:

    $table->date('birthday')->default('0000-00-00')->after('email'); // Pass in the field to the DB as date
    $table->date('hire_date')->default('0000-00-00')->after('birthday'); // Pass in the field to the DB as date

https://i.stack.imgur.com/Vyq2s.png

Once I run my CSV import, the DB returns results as shown below (All blank fields imports from the CSV get kept as "0000-00-00" in the DB which is what I want (This works):

https://i.stack.imgur.com/8L29F.png

Problem: On the API output, this is where things get corrupt - I get a DateTime object returned but all items in the DB that have "0000-00-00" get returned as this response:

    "birthday": {
        "date": "-0001-11-30 00:00:00.000000",
        "timezone_type": 3,
        "timezone": "UTC"
    },
    "hire_date": {
        "date": "-0001-11-30 00:00:00.000000",
        "timezone_type": 3,
        "timezone": "UTC"
    },

My API method:

    public function transform($employee)
    {
        return [
            'birthday' => $employee['birthday'],
            'hire_date' => $employee['hire_date'],
        ];
    }

Possible problem: When I define the two params in the protected $dates that extends Model I get this response, as soon as I remove the two items, then I get a "0000-00-00" response on the API.

How do I have the two items defined as dates, but also get a "0000-00-00" response on the API?

    protected $dates = [
        'birthday',
        'hire_date', // Removing the following items from dates, returns as string
        'created_date',
        'updated_date',
        'touched_at',
        'deleted_at',
    ];
0 likes
1 reply
developer_tech's avatar

I am also having this . Though I am using symfony 2.8. Its strange, I don't understand why symfony converting 0000-00-00 to -0001-11-30 .

Please or to participate in this conversation.