ebrahim
ebrahim

Reputation: 1

How do I convert date and time to timestamp in Laravel 8?

I am using Laravel 8 and Jdf and I want to convert the date and time to timestamp, but it is always 0, I do not know why.

I want the start date and end date to be timestamped

file AdminController.php

public function add_incredible_offers(Request $request) 
{
    $date1=$request->get('date1');
    $date2=$request->get('date2');
    $offers_first_time=getTimestamp($date1,'first');
    $offers_last_time=getTimestamp($date2,'last');

    return $offers_first_time;
}

file helpers.php

See the image here file helpers.php

Upvotes: 0

Views: 510

Answers (1)

Garry
Garry

Reputation: 2370

You're sending parameters to the function in wrong order.

change

$offers_first_time=getTimestamp($date1,'first'); 
$offers_last_time=getTimestamp($date2,'last');

to

 $offers_first_time=getTimestamp('first',$date1); 
 $offers_last_time=getTimestamp('last',$date2);

alternatively you can easily use Carbon.

$offers_first_time = \Carbon\Carbon::make($request->input('date1'))->timestamp;

$offers_last_time = \Carbon\Carbon::make($request->input('date1'))->timestamp;

Upvotes: 3

Related Questions