function makeDateClause() { if (strpos($this->value, "<>")) { $vals = explode("<>", $this->value); $datestamp0 = validateAndConvertToISO($vals[0]); $datestamp1 = validateAndConvertToISO($vals[1]); return "between '{$datestamp0}' and '{$datestamp1}'"; } else { $datestamp = validateAndConvertToISO($this->value); if ($this->exact) { return "= '{$datestamp}'"; } else { if ($this->lessthan) { return "< '{$datestamp}'"; } else { if ($this->greaterthan) { return "> '{$datestamp}'"; } else { return "like '{$datestamp}%'"; //old way // it's a ":" ("like") query - try to figure out if the user means a whole year or month or default to a day $match = preg_match('/^[0-9]{4}$/', $this->value, $matches); if (@$matches[0]) { $date = $matches[0]; } else { if (preg_match('!^\\d{4}[-/]\\d{2}$!', $this->value)) { $date = date('Y-m', $timestamp); } else { $date = date('Y-m-d', $timestamp); } } return "like '{$date}%'"; } } } } }
<hr /> <?php // ----- Fields of type "Date" with wrong values ------------------- //find all fields with faulty dates $res = mysql_query('select dtl_ID, dtl_RecID, dtl_Value, a.rec_Title from recDetails, defDetailTypes, Records a where (a.rec_ID = dtl_RecID) and (dty_ID = dtl_DetailTypeID) and (dty_Type = "date") and (dtl_Value is not null)'); $wascorrected = 0; $bibs = array(); $ids = array(); $dtl_ids = array(); while ($row = mysql_fetch_assoc($res)) { //parse and validate value $row['new_value'] = validateAndConvertToISO($row['dtl_Value']); if ($row['new_value'] == 'Temporal') { continue; } else { if ($row['new_value'] == trim($row['dtl_Value'])) { continue; } } //remove wrong term IDs if (@$_REQUEST['fixdates'] == "1") { if ($row['new_value']) { mysql_query('update recDetails set dtl_Value="' . $row['new_value'] . '" where dtl_ID=' . $row['dtl_ID']); } else { mysql_query('delete from recDetails where dtl_ID=' . $row['dtl_ID']); } $wascorrected++;