0

I am trying to get data that match with my giving time, i pass time as a string for now but it gives error,

here is my code

$final_trade = FinalTrade::where('user_id', $user_id)
        ->where(Carbon::parse('created_at')->format('h:i:s'), '9.30.00')
        ->first();

here is the error,

DateTime::__construct(): Failed to parse time string (created_at) at position 0 (c): The timezone could not be found in the database

3 Answers 3

1

You can use whereTime directly without parsing,

$final_trade = FinalTrade::where('user_id', $user_id)
               ->whereTime('created_at', '=', '9:30:00')
                ->first();
Sign up to request clarification or add additional context in comments.

3 Comments

this works, what if i need to compere time and add hours in it ?
actually i need to get time between range, i just have start time, so i need to add hour in it like start date and end date
@MuhammadArslan, for that you may use accessor, getCreatedAtAttribute and u can return whatever you want.
0

You need to pass date in the parse not string https://carbon.nesbot.com/docs/ Read the docs

2 Comments

what do you means ?
First off there is error in your syntax where expects first parameter to be column's name and you should pass date format like Carbon::parse('2018-02-18 10:00:01') like so
0

The first field in the where method must be the name of the table field

$final_trade = FinalTrade::where('user_id', $user_id)
        ->where('created_at', '9.30.00')
        ->first();

please read this laravel query builder

3 Comments

this always return null
this is the actual date i have, 2018-05-25 09:30:00
if you want to do what you need during the search, or save the time in the created_at table, or use CARBON to format the time to the date and time. although it would be more correct if the table saved the time and not the datetime

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.