BrainPill Posted December 7, 2019 Share Posted December 7, 2019 I want a string input of minutes into minutes with leading zeros I use date() for this <php $time_in_min ='7'; $minutes = date("i" ,$time_in_min) ; var_dump($minutes); ?> but all I get is 00 while i according to the date() param explanation should give a leading zero. Like :07 How should this be solved? Link to comment Share on other sites More sharing options...
niche Posted December 7, 2019 Share Posted December 7, 2019 (edited) Try wrapping this in an if statement that tests for string length: $var = 7; echo sprintf('%02d', $var); Edited December 7, 2019 by niche 1 Link to comment Share on other sites More sharing options...
BrainPill Posted December 7, 2019 Author Share Posted December 7, 2019 yes thanks it worked Link to comment Share on other sites More sharing options...
dsonesuk Posted December 7, 2019 Share Posted December 7, 2019 If you use date() you have to provide a unix timestamp made up of seconds. 7 is seven seconds, therefore minutes indeed will show 00. You need to give 7 min made up as seconds. <!DOCTYPE html> <html> <body> <?php $d=60*7; //60sec x 7 = 7mins echo "Created date is " . date("i", $d); ?> </body> </html> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now