We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Howdy,

    I’m trying to simply set the value of a MySQL `datetime` field to the current time.
    It seems like this should be the way to do it:
    $req = $xpdo->newObject('quoterequest');
    $req->set('query1_datetime', "NOW()");

    But the field never makes it into the bindings array on it’s way to the final sql statement.
    I tried phptype as "datetime" and "string" and the same result for both.

    I have found that taking out the php "continue" statement from xpdoobject.class.php, line 1039, solves the problem for me.
    But I wanted to pass this by the forum first, because it might be a php 4 issue, or maybe I didn’t find the magic combination of parameters in my schema...

                    elseif (in_array($this->_fieldMeta[$_k]['phptype'], array ('timestamp', 'datetime')) && in_array($fieldValue, $this->_currentTimestamps)) {
                        if ($this->_new) {
                            $this->_fields[$_k]= $this->strftime('%Y-%m-%d %H:%M:%S');
                        $fieldType= PDO_PARAM_NULL;

    On another matter related to dates and php4, I had been having difficulty setting MySQL fields of type `date` to anything pre-Unix epoch in php4. I discovered that setting phptype to ’string’ and setting the value in the xpdo object to a string, formatted "yyyy/mm/dd", does the trick.
      Mike Schell
      Lead Developer, MODX Cloud
      Email: [email protected]
      GitHub: https://github.com/netProphET/
      Twitter: @mkschell
    • PHP 4 on most platforms does not support pre-epoch dates.

      If you have the proper datetime fields, you set the value of the PHP variable to the appropriate PHP value; a valid datetime string. You do not pass SQL functions; that is why it is continuing, because you have not provided a valid PHP date value. e.g.
      $agreement->set('submitted', strftime("%Y-%m-%d %H:%M:%S"));

      Take a look at the xPDOObject::set() function and check the switch for the datetime and date cases to see exactly how it is handled.