| ADOdb Library for PHP Manual | ||
|---|---|---|
| Prev | SQLDate | Next |
Returns a string which contains the native SQL functions to format a date or date column $basedate. This is used when retrieving date columns in SELECT statements. For sending dates to the database (eg. in UPDATE, INSERT or the where clause of SELECT statements) use DBDate( ). It uses a $dateFormat string, which supports:
Y: 4-digit Year Q: Quarter (1-4) M: Month (Jan-Dec) m: Month (01-12) d: Day (01-31) H: Hour (00-23) h: Hour (1-12) i: Minute (00-59) s: Second (00-60) w: day of week (0-6 or 1-7 depending on DB) l: day of week (as string - lowercase L) W: week in year (0..53 for MySQL, 1..53 for PostgreSQL and Oracle) A: AM/PM indicator
All other characters are treated as strings. You can also use to escape characters. Available on selected databases, including mysql, postgresql, mssql, oci8 and DB2.
This is useful in writing portable sql statements that GROUP BY on dates. For example to display total cost of goods sold broken by quarter (dates are stored in a field called postdate):
$sqlfn
= $db->SQLDate('Y-QQ','postdate');
# get sql that formats postdate to output 2002-Q1
$sql =
"SELECT $sqlfn,SUM(cogs) FROM table GROUP BY $sqlfn
ORDER BY 1 desc";
| Prev | Home | Next |
| OffsetDate | Up | Affected_Rows |