pocobueno1388 Posted November 3, 2006 Share Posted November 3, 2006 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:28I would greatly appreciate any help =) Link to comment https://forums.phpfreaks.com/topic/26014-converting-datetime-and-time-from-the-database/ Share on other sites More sharing options...
kenrbnsn Posted November 3, 2006 Share Posted November 3, 2006 Use the [url=http://www.php.net/date]date()[/url] and [url=http://www.php.net/strtotime]strtotime()[/url] functions.Ken Link to comment https://forums.phpfreaks.com/topic/26014-converting-datetime-and-time-from-the-database/#findComment-118917 Share on other sites More sharing options...
pocobueno1388 Posted November 3, 2006 Author Share Posted November 3, 2006 I know you use those functions, I am just horrible at using them. I can never get it right. Link to comment https://forums.phpfreaks.com/topic/26014-converting-datetime-and-time-from-the-database/#findComment-118918 Share on other sites More sharing options...
kenrbnsn Posted November 3, 2006 Share Posted November 3, 2006 Example:[code]<?phpecho '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 Link to comment https://forums.phpfreaks.com/topic/26014-converting-datetime-and-time-from-the-database/#findComment-118920 Share on other sites More sharing options...
pocobueno1388 Posted November 3, 2006 Author Share Posted November 3, 2006 That printed"When the server time is 15:40:32 my current time is 3:40 pm"I will play with it and see what I can come up with. Link to comment https://forums.phpfreaks.com/topic/26014-converting-datetime-and-time-from-the-database/#findComment-118925 Share on other sites More sharing options...
kenrbnsn Posted November 3, 2006 Share Posted November 3, 2006 That statement is correct.Ken Link to comment https://forums.phpfreaks.com/topic/26014-converting-datetime-and-time-from-the-database/#findComment-118928 Share on other sites More sharing options...
pocobueno1388 Posted November 3, 2006 Author Share Posted November 3, 2006 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. Link to comment https://forums.phpfreaks.com/topic/26014-converting-datetime-and-time-from-the-database/#findComment-118932 Share on other sites More sharing options...
pocobueno1388 Posted November 3, 2006 Author Share Posted November 3, 2006 hmmm, I have been playing with it, and I'm not having any luck. Link to comment https://forums.phpfreaks.com/topic/26014-converting-datetime-and-time-from-the-database/#findComment-119091 Share on other sites More sharing options...
obsidian Posted November 3, 2006 Share Posted November 3, 2006 [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]<?phpecho "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. Link to comment https://forums.phpfreaks.com/topic/26014-converting-datetime-and-time-from-the-database/#findComment-119103 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.