Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i format time in php

Tags:

php

I have a time returned from database in php as 92500. But i want to format the time as 09:25 how can do this echo date ('H:i',strtotime($row['time'])) .it is outputting 00:00. How can i get 09:25

like image 375
Someone Avatar asked Mar 16 '11 20:03

Someone


People also ask

How can change time in 24 hour format in PHP?

php //current Date, i.e. 2013-08-01 echo date("Y-m-d"); //current Time in 12 hour format, i.e. 08:50:55pm echo date("h:i:sa"); //current Time in 24 hour format, i.e. 18:00:23 echo date("H:i:s"); //current Month, i.e. 08 echo date("m"); //current Month name, i.e. Aug echo date("M"); ?>

What does time () do in PHP?

The time() function returns the current time in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

How do I format in PHP?

The editor provides the document formatting feature for PHP documents. Right-click the editor area and choose Format Document . In order to format the document, it must be syntax-error free. The code formatting normalizes whitespaces, line endings, opening and closing braces, indentation and pretty print spaces.


1 Answers

Actually

$date = '9:25';

echo date ('H:i',strtotime($date));

is working perfectly fine for me.

Returns "09:25".

So i guess it has to be some error with your database value meaning $row['time'] doesn't contain the right value.

like image 110
Alex Bailey Avatar answered Sep 18 '22 20:09

Alex Bailey