What's the trick to inserting a date in a query?

I need the secret decoder ring for this! When I echo it out, $dt->format('Y-m-d') outputs exactly what I would expect: eg. '2021-09-02'. But I have tried a dozen variations and cannot seem to find a way to properly populate the field. I've tried making the stay_date column a date, a jdate, and a plain text field. As a date or jdate field, nothing is populated. When I turn stay_date into a plain text column, it seem to populate an unexpected year value only.

What am I doing wrong here?
Thanks!

PHP:
    $myDb = JFactory::getDbo();
    $myQuery = $myDb->getQuery(true);
    $myQuery->insert('guest_bookings')
      ->set('stay_date = '. $dt->format('Y-m-d'))
      ->set('request_id = ' . $requestId);
    $myDb->setQuery($myQuery);
    $myDb->execute();
 
I don't know from where id $dt, but I think you need to store in database in format 'Y-m-d H:i:s'
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top