I need help with my timestamp...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
midohioit
Forum Newbie
Posts: 18
Joined: Tue Dec 05, 2006 10:19 am

I need help with my timestamp...

Post by midohioit »

While pulling a timestamp off of a mysql database I am having a small issue with the results.

the data on the database looks like this, the column is called start_time:
16:30:00

I want to convert this to make it look cleaner. I am using the following code:

$st = $array[start_time];
......

$startime = date("g:i a", mktime($st));

The following is the result that I get:
4:13 pm

(:13 is what the current time is on the server, not :30 which is part of the data...)
Can someone please tell me why I can not get the minutes? :D
timclaason
Forum Commoner
Posts: 77
Joined: Tue Dec 16, 2003 9:06 am
Location: WI

Timestamp

Post by timclaason »

I always use

Code: Select all

date("H:i:s");
Corvin
Forum Commoner
Posts: 49
Joined: Sun Dec 03, 2006 1:04 pm

Post by Corvin »

Code: Select all

<?php
$startime = date("g:i a", strtotime($st));
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mktime() will not parse strings in the manner you wish. strtotime() will. However you could also ask MySQL to return the result in unix timestamp form.
midohioit
Forum Newbie
Posts: 18
Joined: Tue Dec 05, 2006 10:19 am

thanks!

Post by midohioit »

$startime = date("g:i a", strtotime($st));

was my fix, thank you all for your help!
Post Reply