0

I have a PHP script that's returning values from a database. Specifically a tracking number and a time stamp of when the tracking number was created.

I'm trying to figure out how to format this time stamp the value below is how the time stamp is being returned.

20180828115208

 <div class="resul-count" align="center">
Found <?php echo $query->num_rows; ?> Results.
</div><br>


    if($query->num_rows){
        while($r = $query->fetch_object()){
        ?>
        <div class="result">
                <tr>
<td><?php echo $r->ShipToCompanyorName;   ?></td>
<td><?php echo $r->ShipToAttention; ?></td>
<td><?php echo $r->ShipToAddress1; ?></td>
<td><?php echo $r->ShipToCityorTown;   ?></td>
<td><?php echo $r->ShipToStateProvinceCounty; ?></td>
<td><?php echo $r->ShipToPostalCode; ?></td>
<td><?php echo $r->ShipmentInformationShipmentProcessTimestamp; ?></td>
<td><a href="http://wwwapps.ups.com/WebTracking/track?track=yes&trackNums=<?= $r->PackageTrackingNumber; ?>"><?= $r->PackageTrackingNumber;?></a></td>

  • 1
    Possible duplicate of [Convert from MySQL datetime to another format with PHP](https://stackoverflow.com/questions/136782/convert-from-mysql-datetime-to-another-format-with-php) – wp78de Sep 21 '18 at 21:39

1 Answers1

1

You can use DateTime::createFromFormat

$date = DateTime::createFromFormat('YmdHis', $r->ShipmentInformationShipmentProcessTimestamp);
echo $date->format('Y-m-d'); //output 2018-08-28 or choose whatever format you want
Felippe Duarte
  • 14,901
  • 2
  • 25
  • 29