px_date2string
(PECL paradox >= 1.4.0)
px_date2string — Converts a date into a string.
Description
$pxdoc
, int $value
, string $format
)Turns a date as it stored in the paradox file into human readable format. Paradox dates are the number of days since 1.1.0000. This function is just for convenience. It can be easily replaced by some math and the calendar functions as demonstrated in the example below.
Parameters
-
pxdoc
-
Resource identifier of the paradox database as returned by px_new().
-
value
-
Value as stored in paradox database field of type PX_FIELD_DATE.
-
format
-
String format similar to the format used by date(). The placeholders support by this function is a subset of those supported by date() (Y, y, m, n, d, j, L).
Return Values
Returns TRUE
on success or FALSE
on failure.
Examples
Example #1 Turn a paradox date into a human readable form
<?php
$px = px_new();
/* make up a date as it could be stored in */
/* a date field of a paradox db. */
/* 700000 days since 1.1.0000. */
$days = 700000;
/* Use the calendar functions to print a */
/* human readable format of the date */
echo jdtogregorian($days+1721425)."\n";
/* px_date2string() outputs the same */
echo px_date2string($px, $days, "n/d/Y")."\n";
px_delete($px);
?>
The above example will output:
7/15/1917 7/15/1917
See Also
- px_timestamp2string() - Converts the timestamp into a string.
- jdtogregorian() - Converts Julian Day Count to Gregorian date
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с базами данных
- Расширения для работы с базами данных отдельных производителей
- Paradox File Access
- px_close
- px_create_fp
- px_date2string
- px_delete_record
- px_delete
- px_get_field
- px_get_info
- px_get_parameter
- px_get_record
- px_get_schema
- px_get_value
- px_insert_record
- px_new
- px_numfields
- px_numrecords
- px_open_fp
- px_put_record
- px_retrieve_record
- px_set_blob_file
- px_set_parameter
- px_set_tablename
- px_set_targetencoding
- px_set_value
- px_timestamp2string
- px_update_record
Коментарии
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
}
?>