electricshoe Posted March 27, 2008 Share Posted March 27, 2008 Is there a no leading zero minute variable hidden somewhere in magicland? I'm assuming no since there isn't one in the manual. If not is there an easy way for me to parse it in the date() function instead of writing something complicated? Thanks ten million billion in advance Link to comment https://forums.phpfreaks.com/topic/98215-datei-minutes-leading-zero/ Share on other sites More sharing options...
discomatt Posted March 27, 2008 Share Posted March 27, 2008 <?php $var = date('i'); echo ($var{0} === '0' ? $var{1} : $var); ?> or in 1 line <?php $min = (substr(date('i'), 0, 1) === '0' ? substr(date('i'), 1, 1) : date('i') ); echo $min; ?> Link to comment https://forums.phpfreaks.com/topic/98215-datei-minutes-leading-zero/#findComment-502559 Share on other sites More sharing options...
discomatt Posted March 27, 2008 Share Posted March 27, 2008 Also an alternative: <?php $min = date('i'); settype($min, 'int'); // force it to be an integer, stripping leading zeros echo $min; ?> Link to comment https://forums.phpfreaks.com/topic/98215-datei-minutes-leading-zero/#findComment-502566 Share on other sites More sharing options...
rhodesa Posted March 27, 2008 Share Posted March 27, 2008 also, in one line: $min = (int) date('i'); Link to comment https://forums.phpfreaks.com/topic/98215-datei-minutes-leading-zero/#findComment-502568 Share on other sites More sharing options...
discomatt Posted March 27, 2008 Share Posted March 27, 2008 Ahh, i didn't know you typecast on a per-use basis like in C. Good to know. That last one by rhodesa is by far the best and most efficient, unless you really need it to be a string (i'm not sure why you ever would with php though) Link to comment https://forums.phpfreaks.com/topic/98215-datei-minutes-leading-zero/#findComment-502582 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.