AnotherQuestion Posted September 1, 2009 Share Posted September 1, 2009 I have search & search google to find the answer without success. I have a string which looks like e.g. ' 20090901 ' I would like for it to be echo as 01/09/2009 the format is always the same. Thanks as always Link to comment https://forums.phpfreaks.com/topic/172760-solved-strings/ Share on other sites More sharing options...
p2grace Posted September 1, 2009 Share Posted September 1, 2009 Try this: <?php $str = ' 20090901 '; $date = substr($str,7,2)."/".substr($str,5,2)."/".substr($str,1,4); ?> Link to comment https://forums.phpfreaks.com/topic/172760-solved-strings/#findComment-910591 Share on other sites More sharing options...
kenrbnsn Posted September 2, 2009 Share Posted September 2, 2009 What is the format of the string? YYYYMMDD or YYYYDDMM If it's the first format, you can use strtotime and date <?php $str = '20090901'; echo date('d/m/Y',strtotime($str)); ?> Ken Link to comment https://forums.phpfreaks.com/topic/172760-solved-strings/#findComment-910636 Share on other sites More sharing options...
AnotherQuestion Posted September 4, 2009 Author Share Posted September 4, 2009 it was the first format the code i used was: <table width="345" border="0"> <tr> <td width="128"> </td> <td width="207"><p> </p></td> </tr> <tr> <td><strong>Registration</strong></td> <td><p><?php echo $row_RSVehicles['PKey']; ?></p></td> </tr> <tr> <td><strong>Make</strong></td> <td><p><?php echo $row_RSVehicles['Make']; ?></p></td> </tr> <tr> <td><strong>Model</strong></td> <td><p><?php echo $row_RSVehicles['Model']; ?></p></td> </tr> <tr> <td><strong>Chassis</strong></td> <td><p><?php echo $row_RSVehicles['VehicleNo']; ?></p></td> </tr> <tr> <td><strong>Colour</strong></td> <td><p><?php echo $row_RSVehicles['Car_Colour']; ?></p></td> </tr> <tr> <td><strong>Reg Date</strong></td> <?php $strregdate = $row_RSVehicles['FirstReg'];?> <td><p><?php echo date('d/m/Y',strtotime($strregdate)); ?></p></td> </tr> <tr> <td><strong>Mot </strong></td> <?php $strmot = $row_RSVehicles['MotDue'];?> <td><p><?php echo date('d/m/Y',strtotime($strmot)); ?></p></td> </tr> <tr> <td><strong>Service</strong></td> <?php $strservice = $row_RSVehicles['ServiceDue'];?> <td><p><?php echo date('d/m/Y',strtotime($strservice)); ?></p></td> </tr> <tr> <td><strong>Engine Size</strong></td> <td><p><?php echo $row_RSVehicles['Engine_Size']; ?></p></td> </tr> <tr> <td><strong>Engine No</strong></td> <td><p><?php echo $row_RSVehicles['Engine']; ?></p></td> </tr> <tr> <td><strong>Mileage</strong></td> <td><p><?php echo $row_RSVehicles['Mileage']; ?></p></td> </tr> <tr> <td><strong>Fuel </strong></td> <td><p><?php echo $row_RSVehicles['Fuel']; ?></p></td> </tr> <tr> <td><strong>Tyres</strong></td> <td><p><?php echo $row_RSVehicles['Tyre_Size']; ?></p></td> </tr> <tr> <td> </td> <td><p> </p></td> </tr> <tr> <td><p><a href="Booking.php?RegNo=<?php echo $row_RSVehicles['PKey']; ?>&Acon=<?php echo $row_RSVehicles['AirCon']; ?>">Book a Service</a></p></td> <td><p><a href="VehicleDelete.php?RegNo=<?php echo $row_RSVehicles['PKey']; ?>">Delete Vehicle</a></p></td> </tr> </table> Thank you for that. Link to comment https://forums.phpfreaks.com/topic/172760-solved-strings/#findComment-912564 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.