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
}
?>
px_date2string
(PECL paradox >= 1.4.0)
px_date2string — 日付を文字列に変換する
説明
string px_date2string
( resource
$pxdoc
, int $value
, string $format
)paradox ファイルに保存されている日付を、人間が理解しやすい形式に変換します。 paradox の日付は、0000 年 1 月 1 日からの経過日数で保存されています。 この関数は利便性を高めるためだけのもので、 以下の例のように数学関数やカレンダー関数で同等のことを実現できます。
パラメータ
返り値
成功した場合に TRUE を、失敗した場合に FALSE を返します。
例
例1 paradox の日付を人間が理解しやすい形式に変換する
<?php
$px = px_new();
/* paradox db 形式の日付データを再現します。*/
/* 0000 年 1 月 1 日から 700000 日後です。*/
$days = 700000;
/* カレンダー関数を使用して、人間が理解しやすい形式で */
/* 日付を表示します。 */
echo jdtogregorian($days+1721425)."\n";
/* px_date2string() で同じように出力します。*/
echo px_date2string($px, $days, "n/d/Y")."\n";
px_delete($px);
?>
上の例の出力は以下となります。
7/15/1917 7/15/1917
john dot navratil at sbcglobal dot net
21-Dec-2010 09:52
