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

shahr's avatar
Level 10

Undefined array key "year"

I installed https://github.com/morilog/jalali package,

I want to convert it to a timestamp.

public function store(Product $product, Warranty  $warranty, Request $request)
{
    $date = $request->post('new_date');
    $timestamp = Jalalian::fromFormat('Y/m/d H:i:s', $date)->getTimestamp();
    dd($timestamp);
0 likes
2 replies
LaryAI's avatar
Level 58

The error "Undefined array key 'year'" is most likely caused by an invalid date format being passed to the fromFormat method of the Jalalian class.

Make sure that the date format passed to fromFormat matches the format of the $date variable.

For example, if the $date variable is in the format "1399/05/25 12:30:00", the correct format string to pass to fromFormat would be "Y/m/d H:i:s".

Here's an updated version of the code with the correct format string:

public function store(Product $product, Warranty $warranty, Request $request)
{
    $date = $request->post('new_date');
    $timestamp = Jalalian::fromFormat('Y/m/d H:i:s', $date)->getTimestamp();
    dd($timestamp);
}
MohamedTammam's avatar

From the docs I see that you're using the correct method getTimestamp, what's your problem?

Please or to participate in this conversation.