Kairu Posted December 31, 2006 Share Posted December 31, 2006 Is it possible to formate a timestamp (ex: what NOW() would output) Into just the current time in the 12 hour format? I know this can be done through long calculations, but I was hoping there was a format function? Quote Link to comment https://forums.phpfreaks.com/topic/32416-solved-formatting-timestamps/ Share on other sites More sharing options...
brendandonhue Posted January 1, 2007 Share Posted January 1, 2007 http://php.net/date Quote Link to comment https://forums.phpfreaks.com/topic/32416-solved-formatting-timestamps/#findComment-150567 Share on other sites More sharing options...
Kairu Posted January 1, 2007 Author Share Posted January 1, 2007 Theres.... a problem?.... Eh... this makes no sense in my mind.$text = "[" . date("h:ia", $txt[(($i*3)+2)]) . "] " . $text;When I do it like that, I ALWAYS get 7:33pm.....When I do it like this:$text = "[" . $txt[(($i*3)+2)] . "] " . $text;I get the proper time stored in the variable, only its the very large and bulky timestamp.Please don't request the code.... It's 19KB large.... But if you ask, I'll give it. Quote Link to comment https://forums.phpfreaks.com/topic/32416-solved-formatting-timestamps/#findComment-150577 Share on other sites More sharing options...
dcro2 Posted January 1, 2007 Share Posted January 1, 2007 We probably need part of it to understand what $txt[] is... Quote Link to comment https://forums.phpfreaks.com/topic/32416-solved-formatting-timestamps/#findComment-150579 Share on other sites More sharing options...
Nhoj Posted January 1, 2007 Share Posted January 1, 2007 [code=php:0]$now = '2006-12-31 19:51:21';function format_time($now) { $time = explode(' ', $now); $time[2] = explode('-', $time[0]); $time[3] = explode(':', $time[1]); $time = mktime($time[3][0], $time[3][1], $time[3][2], $time[2][1], $time[2][2], $time[2][0]); $time = date('h:i:s A', $time); return $time;}echo format_time($now);[/code]Made this myself, just for you...I think it's what you wanted... Quote Link to comment https://forums.phpfreaks.com/topic/32416-solved-formatting-timestamps/#findComment-150581 Share on other sites More sharing options...
Kairu Posted January 1, 2007 Author Share Posted January 1, 2007 I can quite easily explain that :P And it wouldent tell you anyway, since it's a database pull.What txt[] is, is a hell of a lot of rows of data pulled from a database. Every fourth entry in txt[] is a timestamp, regular format. "2006-12-30 10:50:31" is actually one of the entries. But after running through date() as shown above.... it ouputs as 7:33pm (Or, more accurately, in that example with the code, it would look like this:[7:33pm] Kairu: Test TextAnd when not formatted:[2006-12-30 10:50:31] Kairu: Test TextAdded: Thank you [i]very[/i] much Nhoj. It works quite well! [img]http://graphics4.gaiaonline.com/images/template/smiles/icon_3nodding.gif[/img] Quote Link to comment https://forums.phpfreaks.com/topic/32416-solved-formatting-timestamps/#findComment-150583 Share on other sites More sharing options...
Kairu Posted January 1, 2007 Author Share Posted January 1, 2007 Um.... Is their any reason that can be seen that would prevent something like this from working?$output = "<option selected value=\"b\">" . format_time(NOW()) . "</option>";echo $output;Actoually this wont work either.....$output = "<option selected value=\"b\">" . NOW() . "</option>";echo $output;They just.... I dunno. They don't output errors or anything, they (Timestamp and formatted timestamp) just.... prevent $output from echoing..... at all. Quote Link to comment https://forums.phpfreaks.com/topic/32416-solved-formatting-timestamps/#findComment-150611 Share on other sites More sharing options...
sasa Posted January 1, 2007 Share Posted January 1, 2007 try[code]<?php$t='2006-12-30 19:50:31';echo date('h:ia',strtotime($t));?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32416-solved-formatting-timestamps/#findComment-150624 Share on other sites More sharing options...
Kairu Posted January 1, 2007 Author Share Posted January 1, 2007 Thats an old problem.... o.0 I guess I should have started a new topic...... Quote Link to comment https://forums.phpfreaks.com/topic/32416-solved-formatting-timestamps/#findComment-150626 Share on other sites More sharing options...
emehrkay Posted January 1, 2007 Share Posted January 1, 2007 so you are just trying to format mysql datetime to utc?just do strtotime('2007-12-31 00:00:00');its the same astime(); off by the hours min and seconds, it works though Quote Link to comment https://forums.phpfreaks.com/topic/32416-solved-formatting-timestamps/#findComment-150627 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.