0

Long story short, client's hosting is using php 5.2.5 and i desperately need to use jsonSerialize interface to change the json_encode() datetime format to dd/mm/yyyy hh:mm:ss when ReturnDatesAsStrings option is specified in the mssql connection. The interface came with 5.4. Does anyone know some equivalent for that purpose? Please note i cannot use date_format on a specific field because the dataset changes at runtime and i don't know how many datetime fields there will be. Point it out please.

Wushel
  • 1
  • 1
  • 1
    Side note. The version 5.2.5 was released on 8th November 2003 and is therefore almost [13 years old](https://www.php.net/releases/index.php#5.2.5) Good first step would be to ask client why do they want to continue on outdated version and what stops them from upgrading. – Pavel Janicek Aug 03 '20 at 10:52
  • Maybe a similar approach as https://stackoverflow.com/a/6836658/1427878 could somehow help you here. But, same warning contained in that answer as well - these PHP versions are _ancient_. – CBroe Aug 03 '20 at 10:59
  • 1
    Also version 5.6 is one year and 8 month after end of life. So there will no security fixes anymore! Don't try to get some fuctionality to be backported to such old system. Try to update your server and your application to at least 7.3 better 7.4! – Thomas Aug 03 '20 at 11:34
  • thank you guys i know the update is the best fix ever i already have the code working on 7.4 unluckely the system administrator who should do the upgrade won't be back prior to Semptember 1st meanwhile i have to find a temporarely workaround – Wushel Aug 03 '20 at 12:40

1 Answers1

0

well i found a workaround by myself, it's pretty ugly but it works for now basically i find and overwrite any datetime inside the associative array before to call json_encode

    foreach( sqlsrv_field_metadata( $sth ) as $metaData ) {
      $type = $metaData["Type"];
      $name = $metaData["Name"] ;
      if ($type == 93) {
         $strdate =  strtotime($rows[0][$name]);
         $date = date("d/m/Y H:i:s.u", $strdate);
         $rows[0][$name]=$date;
      }
    }         
Wushel
  • 1
  • 1