Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: remove seconds off of returned time value

Tags:

php

I need to remove the seconds off of a returned time value. I get

12:00:00

I want

12:00pm

I tried using date() but it kept returning the time as 1:00am for everything.

echo date('g:ia', $timestamp);
like image 766
Plummer Avatar asked Jan 18 '13 03:01

Plummer


1 Answers

If you only need to remove seconds (not PM needed), you can use both MYSQL or php:

MYSQL:

SELECT SUBSTRING(SEC_TO_TIME(seconds), 1, 5);

PHP:

$cleantime=substr($time,0,-3);

both will strip off seconds and keep hours and minutes

thanks to Jahanzeb for enhancing the PHP version to support also > 99 hours

like image 151
Luca C. Avatar answered Nov 15 '22 14:11

Luca C.