Insert Date Field in Plugin

By Ryan - August 26, 2019

Hi, i have created the plugin below that creates a record in a log table each time a particular user saves a record in a master table. 

However i can't get the date (masterRefDate) to insert correctly. The date appears to be broken into it's year month and date components, how do i recombine them?

Thanks,

Ryan

addAction('record_postsave', 'plugin_addRevision', null, 4);

   function plugin_addRevision() {

  	global $SETTINGS, $CURRENT_USER, $tableName, $isNewRecord, $oldRecord;

  	if ($CURRENT_USER['username'] == 'admin') {

  		if ($tableName == 'mastertable')	{

  			$tablename = 'logtable';
  			$colsToValues = array(); // 
  			$colsToValues['createdDate='] = 'NOW()';
  			$colsToValues['updatedDate='] = 'NOW()';
  			$colsToValues['createdByUserNum' ] = $CURRENT_USER['num'];
  			$colsToValues['updatedByUserNum' ] = $CURRENT_USER['num'];

  			$colsToValues['ref'] = @$_REQUEST['masterRef'];
  			$colsToValues['refDate=']  = $_REQUEST['masterRefDate'];

  			$hideMissingFieldErrors = true;
  			$newRecordNum = mysql_insert( $tablename, $colsToValues, $hideMissingFieldErrors );
  		}
}
}

By Ryan - August 27, 2019

Worked perfectly, thanks Daniel.