yandoo Posted January 10, 2007 Share Posted January 10, 2007 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 ThanksTom Please help Link to comment https://forums.phpfreaks.com/topic/33576-adding-extra-0-digit-to-minutes-time-in-php/ Share on other sites More sharing options...
taith Posted January 10, 2007 Share Posted January 10, 2007 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 https://forums.phpfreaks.com/topic/33576-adding-extra-0-digit-to-minutes-time-in-php/#findComment-157246 Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 remove the   stuff,(*both of them) btw, i still think there is a bug with this forum... Link to comment https://forums.phpfreaks.com/topic/33576-adding-extra-0-digit-to-minutes-time-in-php/#findComment-157247 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.