John Davidson

php - Laravel SQL query midnight time not showing

0 comments
Message:


I am making a schedule display system and it shows the schedules of ferries. my problem is if I dont put midnight time in order then query skips midnight time and displays morning instead


EXAMPLE:-


if i put data in order like this



  1. 1:30 am

  2. 6:30 am

  3. 7:30 am


then the times show correctly, but if its not in order



  1. 6:30 am

  2. 7:30 am

  3. 1:30 am


then the query skips the 1:30 am and goes straight to 6:30 to display.


Here is my laravel SQL Query:- if departure time is greater than current time then show the next available one


         DB::table('ferries')->groupBy('ferry_name')
->whereTime('departure_time', '>', Carbon::now()->toTimeString())
->whereIn('schedule_type', ['Weekday'])
->where('terminal_name', $terminal_name)->get()->all();


My Answer:
>where('departure_time', '>', Carbon::now())
>orderBy('departure_time')
>first();

Rate this post

4 of 5 based on 8507 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us