note 101509 modified in function.px-date2string by danbrown
| From: | danbrown@php.net | Date: | Tue, 21 Dec 2010 17:57:10 +0000 |
| Subject: | note 101509 modified in function.px-date2string by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-175114@lists.php.net to get a copy of this message | ||
Date fields are retrieved as the number of days since 0 A.D. (I think), but not as anything
resembling a date. If you are exporting this data, you must used this function to convert. Read
the schema first to determine which fields are date fields...
<?php
$schema = $pxdoc->get_schema();
$dateFields = array();
foreach ($schema as $key => $attrs) {
if ($attrs["type"] == PX_FIELD_DATE) // Collect list of "date" columns
$dateFields[] = $key;
}
?>
An export to a CSV format, for example, could them be written...
<?php
for ($rec = 0; $rec < $totRecs; ++$rec) {
$arr = $pxdoc->get_record($rec);
foreach ($dateFields as $key) {
$arr[$key] = $pxdoc->date2string($arr[$key], "m/d/Y");
}
fputcsv(STDOUT, $arr); // STDOUT only available with CLI
}
?>
--was--
Date fields are retrieved as the number of days since 0 A.D. (I think), but not as anything
resembling a date. If you are exporting this data, you must used this function to convert. Read
the schema first to determine which fields are date fields...
$schema = $pxdoc->get_schema();
$dateFields = array();
foreach ($schema as $key => $attrs) {
if ($attrs["type"] == PX_FIELD_DATE) // Collect list of "date" columns
$dateFields[] = $key;
}
An export to a CSV format, for example, could them be written...
for ($rec = 0; $rec < $totRecs; ++$rec) {
$arr = $pxdoc->get_record($rec);
foreach ($dateFields as $key) {
$arr[$key] = $pxdoc->date2string($arr[$key], "m/d/Y");
}
fputcsv(STDOUT, $arr); // STDOUT only available with CLI
}
http://php.net/manual/en/function.px-date2string.php