Format time without leading zero

I have in a Blueprint a filed that is type=time

I want the output without leading 0 and the full-time without the 00 at the end.

Example:

in txt-file = 09:00
output = 9

or

in txt-file = 09:15
output = 9.15

i have tested this with:
date("%k.%M")
and
date("l.i")

but this will not function…

can i take the idate-Functions there as well?

I think you want:

date('g:ia')

I think you need to convert time into proper time though, like an ISO date and time. For me in my project this looked like this:

 $estartdate = $page->startdate();
 $estarttime = $page->starttime();
 $estartisoDate = date('Y-m-d\TH:i:s', strtotime("$estartdate $estarttime"));
 $englishdate = date('l, F j: g:ia', strtotime($estartisoDate));

Which will combine separate date and time fields into a full ISO date and time, then manipulate it to be a human readable. $englishdate will equal:

Monday, October 22: 2:00pm

i think you just need date('g:ia') for what you want.

Actually, since this is just a time field, I think this might be better (untested):

$yourtime = strtotime($page->yourtimefield());
$formattedtime = time('g:ia', $yourtime);

I always forget theres a time() as well as date(), but I suspect this will return the same result:

$formattedtime = date('g:ia', $yourtime);

I have tested…

$starttime = $page->starttime();
$formatstarttime = date('H.i', strtotime($startzeit));

But this will get me the Time example: 19.00
An i want to have when it is 19.00 --> 19
And when it is 19.15 --> 19.15

So i tested this:

$starttime = $page->starttime();
$formatstarttime = trim(date('H.i', strtotime($startzeit)), ".00");

But this cuts the time example 18.30 to 18.3

I see. Maybe try string replace (untested)…

$startzeit = $page->starttime();
$formatstarttime = date('H.i', strtotime($startzeit));
$mytime = str_replace(".00", " ", $formatstarttime);

Thats it!
Thank You James!

1 Like

Shorter version:

$formattedStarttime = $page->date('g:i', 'starttime');
mytime = str_replace(".00", " ", $formattedStarttime);

Or as a one liner without any string replacement stuff:

echo $page->date('i', 'startttime') == '00'? $page->date('g', 'starttime'): $page->date('g:i','startime');