date fields in PHP 7.2 and 7.4

53 views
Skip to first unread message

Carlos H. Cantu

unread,
Nov 8, 2023, 8:39:24 AM11/8/23
to Firebird-PHP
It seems that something changed between PHP 7.2 and 7.4 when the ibase driver is used to retrieve date fields. The following code produces different results in 7.2 and 7.4:

example code:

    $result = ibase_query("select first 1 INSERIDO from dados", $conexao);
    $row = ibase_fetch_object($result);
echo 'Puro = ' . $row->INSERIDO . '<br />';
echo 'VarDump = ' . var_dump($row->INSERIDO) . '<br />';
echo 'mktime original = ' . substr($row->INSERIDO, 5, 2) . '|' . substr($row->INSERIDO, 8, 2) . '|' . substr($row->INSERIDO, 0, 4) . '<br />';  
$inserido = mktime(0, 0, 0, substr($row->INSERIDO, 5, 2), substr($row->INSERIDO, 8, 2), substr($row->INSERIDO, 0, 4)) . '<br />';
echo 'strftime = ' . strftime('%d.%m.%y',$inserido) . '<br />';
    ibase_close($conexão);


In 7.2:

Puro = 2002-10-29
string(10) "2002-10-29" VarDump =
mktime original = 10|29|2002
strftime = 29.10.02

In 7.4:

Puro = 10/29/2002
string(10) "10/29/2002" VarDump =
mktime original = /2|02|10/2
strftime =

Obviously 7.2 is returning y-m-d and 7.4 returns m-d-y.

Question is: what is the correct way to get a date or timestamp from firebird and convert it to a "php" timestamp that can be used with strftime and other php date/time functions? Ideally, code should work correctly in any PHP 7.x and 8.x.

Carlos

martin.koeditz

unread,
Nov 8, 2023, 10:23:29 AM11/8/23
to Firebird-PHP
Hi Carlos,

please refer to the documentation. There is an php.ini param for setting the date formats.

Please check if this fixes your issue.

Martin

Carlos H. Cantu

unread,
Nov 8, 2023, 12:33:49 PM11/8/23
to firebi...@googlegroups.com
I just checked (using ini_get) and the three parameters returns the same configuration in 7.2 and 7.4, but for some reason the content returned by the firebird driver is different:

echo ini_get('ibase.dateformat') . '<br />';
echo ini_get('ibase.timestampformat') . '<br />';
echo ini_get('ibase.timeformat') . '<br />';

returns the same for 7.2 and 7.4:

%Y-%m-%d
%Y-%m-%d %H:%M:%S
%H:%M:%S

[]s
Carlos

--
You received this message because you are subscribed to the Google Groups "Firebird-PHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-php...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/firebird-php/0e3ad90f-dc59-477b-8515-4b311b835ffen%40googlegroups.com.

Matthias Hanft

unread,
Nov 8, 2023, 1:50:05 PM11/8/23
to firebi...@googlegroups.com
Wonder how you can use ibase functions with PHP 7.4 because for
example page https://www.php.net/manual/en/function.ibase-query.php
says "PHP7 < 7.4.0" (and PHP 8 apparently not at all).

That's why I switched to PDO (not too much work). With PDO, you
can select date/time formats directly in PHP:

define('FB_IP', '127.0.0.1');
define('FB_CHARSET', 'ISO8859_1');

function GetPDO($aDatabaseName, $aUN='username', $aPW='password') {
$myPDO=new PDO('firebird:dbname='.FB_IP.':'.$aDatabaseName.';charset='.FB_CHARSET.';dialect=3', $aUN, $aPW);
// for example, either...
$myPDO->setAttribute(PDO::FB_ATTR_DATE_FORMAT, '%s'); // Unix Timestamp
$myPDO->setAttribute(PDO::FB_ATTR_TIME_FORMAT, '%s'); // Unix Timestamp
$myPDO->setAttribute(PDO::FB_ATTR_TIMESTAMP_FORMAT, '%s'); // Unix Timestamp
// ...or...
// $myPDO->setAttribute(PDO::FB_ATTR_DATE_FORMAT, '%Y-%m-%d'); // 2020-12-31
// $myPDO->setAttribute(PDO::FB_ATTR_TIME_FORMAT, '%H:%M:%S'); // 12:34:56
// $myPDO->setAttribute(PDO::FB_ATTR_TIMESTAMP_FORMAT, '%Y-%m-%d %H:%M:%S'));
// ...or whatever format you want
return $myPDO;

The format specifiers come from the C function "strftime":
https://man7.org/linux/man-pages/man3/strftime.3.html

(I guess/hope this is independent from PHP's "strftime" which is
deprecated: https://www.php.net/manual/en/function.strftime.php )

-Matt

Carlos H. Cantu

unread,
Nov 8, 2023, 2:10:40 PM11/8/23
to firebi...@googlegroups.com
It works fine with 7.2 and probably with 7.4 (when I find out how to solve the problem with the dates/timestamps).

Carlos

--
You received this message because you are subscribed to a topic in the Google Groups "Firebird-PHP" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/firebird-php/JkTpxvqkXbI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to firebird-php...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/firebird-php/14cc9298-1906-37b9-f514-44c9503fb66e%40hanft.de.

martin.koeditz

unread,
Nov 9, 2023, 6:50:33 AM11/9/23
to Firebird-PHP
We'll do a check for this.

Martin

Carlos H. Cantu

unread,
Nov 24, 2023, 7:54:09 PM11/24/23
to Firebird-PHP
Hi!

Any news about this?

Carlos

Köditz, Martin

unread,
Nov 27, 2023, 1:48:18 AM11/27/23
to firebi...@googlegroups.com
Hi,

Not yet. I‘m currently on holidays. But I will try to check it this week.

Martin 

Von meinem iPhone gesendet

 

 

E-Mail: Martin....@it-syn.de
Festnetz: +49 5131 46358 - 300
Mobil: +49 174 9095174

Adresse:
Dieselstraße 18
30827 Garbsen

Geschäftsführer: Jörg Obermann
USt.-ID: DE266943764
Gerichtsstand: Amtsgericht Hannover HRB 204887

   tweeter

Vertraulichkeitshinweis: Die in dieser E-Mail enthaltenen Informationen sind vertraulich zu behandeln und sind nur für die Personen oder das Unternehmen bestimmt, an welche sie tatsächlich gerichtet sind. Sollten Sie diese Nachricht aufgrund eines Übermittlungsfehlers erhalten haben, bitten wir Sie den Versender der Nachricht unverzüglich zu informieren. Ebenso bitten wir Sie, den Inhalt Dritten gegenüber vertraulich zu behandeln und ihn nicht weiter zu verbreiten.

 

Sicherheitshinweis: Das Internet ist kein sicheres Kommunikationsmedium. Im Rahmen unseres Qualitätsmanagements und aller gebotenen Sorgfalt wurden Schritte eingeleitet die einen Virenbefall dieser E-Mail weitgehend ausschließen, aber wegen der Beschaffenheit des Übertragungsmediums nicht garantiert werden können.

Am 25.11.2023 um 00:54 schrieb Carlos H. Cantu <warmb...@gmail.com>:

Hi!

martin.koeditz

unread,
Dec 4, 2023, 8:24:03 AM12/4/23
to Firebird-PHP
Hi,

I checked the example. I cannot find any errors or changes here. I used following code on both versions:

<?php

   $sql = 'select cast(MON$TIMESTAMP as date) AS MONTS from mon$statements where mon$timestamp is not null;';

    $result = ibase_query($sql, $conexao);
    $row = ibase_fetch_object($result);
echo 'Puro = ' . $row->MONTS . '<br />';
echo 'VarDump = ' . var_dump($row->MONTS) . '<br />';
echo 'mktime original = ' . substr($row->MONTS, 5, 2) . '|' . substr($row->MONTS, 8, 2) . '|' . substr($row->MONTS, 0, 4) . '<br />';  
$inserido = mktime(0, 0, 0, substr($row->MONTS, 5, 2), substr($row->MONTS, 8, 2), substr($row->MONTS, 0, 4)) . '<br />';

echo 'strftime = ' . strftime('%d.%m.%y',$inserido) . '<br />';
    ibase_close($conexao);

?>

In both cases the output looks that way:

Puro = 2023-12-04
string(10) "2023-12-04" VarDump =
mktime original = 12|04|2023
strftime = 04.12.23

Do you used the same system? Maybe there are differences between the OS?

Kind Regards
Martin


Carlos H. Cantu

unread,
Dec 4, 2023, 8:57:33 AM12/4/23
to firebi...@googlegroups.com
I'm using the same system to do the tests, which is a shared host server with Linux and CPANEL installed. I use the CPANEL MultiPHP manager to change the PHP version used by a specific domain. Everything works fine with PHP 7.2, but when I change to 7.4, the driver seems to not respect the defined format when outputting the dates :-(

Carlos

Reply all
Reply to author
Forward
0 new messages