Jump to content

Converting datetime and time from the database.


pocobueno1388

Recommended Posts

I am horrible at converting dates and times, so I need your help ^^

How would I convert

[code]2006-11-02 18:39:11[/code]

From the database and just have the time converted to 'non-military' time?

It is a 'datetime' and the row is called "post_time".

When the server time is "21:28:30" my current time is 9:28


I would greatly appreciate any help =)
Example:
[code]<?php
echo 'When the server time is ' . date('H:i:s',strtotime($post_time)) . ' my current time is ' . date('g:i a',strtotime($post_time));
?>[/code]

I always have to refer to the manual page for the date() function, since I never remember which format character to use for the time.

Ken
[quote author=pocobueno1388 link=topic=113687.msg462215#msg462215 date=1162526990]
Yes, it is. Now how do I print that with the date it was posted next to it?

It started like this "2006-11-02 18:39:11" and ended up with only the time, lol.
[/quote]

That's where reading the [url=http://www.php.net/date]manual entry for date()[/url] comes in handy. There is a full listing of all the delimiters that are possible to use within the date() function to get what you're after. For instance:
[code]
<?php
echo "The date is " . date('n/j/Y', strtotime($post_time)) . "<br />\n";
echo "The time is " . date('g:i:s a', strtotime($post_time));
?>
[/code]

Notice that the first line outputs date, the second does time, but the syntax of the lines is identical, and I'm even using the same timestamp for both. It all comes down to what format you request the date() function to output your results.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.