downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

px_delete_record> <px_create_fp
[edit] Last updated: Fri, 25 May 2012

view this page in

px_date2string

(PECL paradox >= 1.4.0)

px_date2string 日付を文字列に変換する

説明

string px_date2string ( resource $pxdoc , int $value , string $format )

paradox ファイルに保存されている日付を、人間が理解しやすい形式に変換します。 paradox の日付は、0000 年 1 月 1 日からの経過日数で保存されています。 この関数は利便性を高めるためだけのもので、 以下の例のように数学関数やカレンダー関数で同等のことを実現できます。

パラメータ

pxdoc

px_new() が返す paradox データベースのリソース ID。

value

PX_FIELD_DATE 型の paradox データベースフィールドに格納される値。

format

date() で使用するのと同じ形式の文字列フォーマット。 この関数がサポートするプレースホルダは、date() でサポートしているもの (Y, y, m, n, d, j, L) のサブセットです。

返り値

成功した場合に 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

参考



add a note add a note User Contributed Notes px_date2string
john dot navratil at sbcglobal dot net 21-Dec-2010 09:52
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
}
?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites