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

shahr's avatar
Level 10

How to change to timestamp

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)
{
    $colors = $request->post('color');
    $date = $request->post('date');
    $time = $date->getTimestamp();
    dd($time);
0 likes
1 reply
LaryAI's avatar
Level 58

To convert a Jalali date to a timestamp, you can use the makeCarbon method provided by the morilog/jalali package. Here's an example:

use Morilog\Jalali\Jalalian;

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

In this example, we're using the fromFormat method to create a Jalalian instance from the input date string. We're assuming that the input date string is in the format Y/m/d H:i:s, but you can adjust this to match your specific input format.

Once we have a Jalalian instance, we can call the getTimestamp method to get the Unix timestamp equivalent. This timestamp can then be used with any PHP function that expects a Unix timestamp.

Note that the getTimestamp method returns the timestamp in seconds, so you may need to multiply it by 1000 if you need it in milliseconds.

Please or to participate in this conversation.