I have a datetime string of format 'Y-m-d H:i:s', and datetime value as '2018-01-30 07:11:21'.

$carbon_obj = Carbon::createFromFormat('Y-m-d H:i:s' , '2018-01-30 07:11:21','America/Chicago'); 

How do it get the Unix timestamp from this carbon object?

2 Answers

just add timestamp at the back of your code.

$carbon_obj = Carbon::createFromFormat('Y-m-d H:i:s' , '2018-01-30 07:11:21','America/Chicago')->timestamp; 

or

$carbon_obj = Carbon::createFromFormat('Y-m-d H:i:s' , '2018-01-30 07:11:21','America/Chicago'); $carbon_obj->timestamp; 

If you have data missing error. missing it is the data your passed it not a complete date format.

Try this.

$timestp = Carbon::createFromFormat('Y-m-d H:i:s', Carbon::parse($trans['transaction_datetime']) ,Setting::get('timezone'))->timestamp; 
5

You can use Carbon::shiftTimezone to change the timezone without changing the dates and time.

$dt = Carbon::parse('2020-03-27'); dump($dt); //2020-03-27 00:00:00.0 Asia/Kolkata (+05:30) dump($dt->shiftTimezone('utc')); //2020-03-27 00:00:00.0 UTC (+00:00) 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.