too long

I am using PHP to query an AS400 DB2 database. The time(ADACTM) is saved in the table like; ADACTM field in DB2 Table

I need to convert this to a human-readable format like 9:46:23.

I am currently doing this in PHP;

$adactm = str_split($fin2['ADACTM']);
$adactm = "$adactm[0]$adactm[1]:$adactm[2]$adactm[3]:$adactm[4]$adactm[5]";

The problem is, when the time doesn't have a 2-digit hour, PHP thinks array position 0 is actually position 1. So the time shows like;

94:62:3

If anyone has a way to fix this, it would be greatly appreciated. Thanks!

Pad the string before you split it:

$rawtime = '94623';
$padded = str_pad($rawtime, 6, '0', STR_PAD_LEFT); // 094623

Then split/mangle as before

Sorry, no better idea than this:

$adactm = str_split($fin2['ADACTM']);

if (count($adactm) == 5) {
    $adactm = "$adactm[0]:$adactm[1]$adactm[2]:$adactm[3]$adactm[4]";
} else {
    $adactm = "$adactm[0]$adactm[1]:$adactm[2]$adactm[3]:$adactm[4]$adactm[5]";
}