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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.