mardi 9 février 2021

Postgres filter by date not working in Laravel

I am using a query to sort some of my appointments from the appointment date,

this is my code

 $appointments = $appointments
          ->where(DB::raw( "to_char((appointments.response::json->>'datetime')::timestamp, 'MM/DD/YYYY HH:MM:SS')" ), '>=', $start_date_format)
          ->where(DB::raw( "to_char((appointments.response::json->>'datetime')::timestamp, 'MM/DD/YYYY HH:MM:SS')" ), '<=', $end_date_format);

When I debug

dd($appointments->select(DB::raw( "to_char((appointments.response::json->>'datetime')::timestamp, 'MM/DD/YYYY HH:MM:SS')"))->get());
t\Collection {#1800 ▼
  #items: array:22 [▼
    0 => {#1829 ▼
      +"to_char": "01/20/2021 11:01:00"
    }
    1 => {#1831 ▼
      +"to_char": "01/22/2021 02:01:00"
    }
    2 => {#1828 ▼
      +"to_char": "01/19/2021 02:01:00"
    }
    3 => {#1835 ▼
      +"to_char": "01/21/2021 02:01:00"
    }
    4 => {#1830 ▼
      +"to_char": "01/05/2021 01:01:00"
    }
    5 => {#1832 ▼
      +"to_char": null
    }
    6 => {#1833 ▼
      +"to_char": "03/28/2021 11:03:00"
    }
    
  ]

when i debug dd($start_date_format); - format would be like these "12/31/2020 00:00:00"

when i sort my date it works , but if i change the year it wont work , is there anything i had done wrong



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3tH2eYk
via IFTTT

Aucun commentaire:

Enregistrer un commentaire