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 remove 00:00:00 in $date?

I want to remove 00:00:00 in $date, How do I do it?

public function store(Product $product, Warranty $warranty, Request $request)
{
    $date = $request->post('new_date'.' '.'00:00:00');
    $timestamp = Jalalian::forge($date)->getTimestamp(); // 1333857600
    dd($timestamp, $date);
}
0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

To remove the "00:00:00" from the date, you can use the PHP strtotime() function to convert the date string to a Unix timestamp, and then use the date() function to format the timestamp as a string without the time component. Here's an example:

public function store(Product $product, Warranty $warranty, Request $request)
{
    $date = $request->post('new_date');
    $timestamp = strtotime($date);
    $date_without_time = date('Y-m-d', $timestamp);
    dd($timestamp, $date_without_time);
}

In this example, we first retrieve the date string from the request without the "00:00:00" time component. We then use strtotime() to convert the date string to a Unix timestamp. Finally, we use date() to format the timestamp as a string without the time component, using the 'Y-m-d' format string.

Note that the resulting date string will be in the format 'YYYY-MM-DD'. If you need a different format, you can adjust the format string passed to date().

1 like

Please or to participate in this conversation.