Jump to content

Adding extra 0 digit to minutes time in php


yandoo

Recommended Posts

Hi,

ive used the following code to enable the time time automatically appear in a text field on a form.

<?php
$now = getdate(time('G'));
echo $now['hours'] . ":" .  $now['minutes'] . ":" . $now['seconds'];
?>

The problem is this, it appears as 11:7:01 I need the time to appear as 11:07:01 requiring the extra 0 digit to be added! If the time in mins is 11:10:01 then its ok, it is just when the time in mins is before 10 the 0 digit doesnt appear...


I need it to fulfill the format requirements by mysql.

Many Thanks

Tom
Please help
not tested, but should work :-)
[code]
<?php
$now = getdate(time('G'));
$hours = $now['hours'];
$minutes = str_pad($now['minutes'], 2, "0", STR_PAD_LEFT); 
$seconds = str_pad($now['seconds'], 2, "0", STR_PAD_LEFT); 
echo $hours.":". $minutes.":".$seconds;
?>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.