kemper Posted June 2, 2007 Share Posted June 2, 2007 I have display of: <tr> <td width='124' valign='top'> <p style='margin-top: 0; margin-bottom: 0'><b>Date:</b></td> <td width=216' valign='top'> <p style='margin-top: 0; margin-bottom: 0'>".$data['date']=date("D, F j, Y",strtotime($date['date']))."</td> </tr> <tr> <td width='124' valign='top'> <p style='margin-top: 0; margin-bottom: 0'><b>Time/Notes:</b></td> <td width='216' valign='top'> <p style='margin-top: 0; margin-bottom: 0'>".$data['time']."</td> </tr> The time displays as 00:00:00, since mysql field is set up as: `time` time NOT NULL default '00:00:00' How can I change this to display as hh(12 hr):mm am/pm (%I:%M %p)? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/ Share on other sites More sharing options...
AndyB Posted June 2, 2007 Share Posted June 2, 2007 D, F j, Y h:i a Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-266920 Share on other sites More sharing options...
kemper Posted June 2, 2007 Author Share Posted June 2, 2007 I am not sure how to code that for time. I tried unsuccessfully as: <p style='margin-top: 0; margin-bottom: 0'>'".$data['time']=time("D, F j, Y h:i a",strtotime($time['time']))."'</td> Suggestions would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-266927 Share on other sites More sharing options...
fert Posted June 2, 2007 Share Posted June 2, 2007 <p style='margin-top: 0; margin-bottom: 0'>'".date("D, F j, Y h:i a",strtotime($time['time']))."'</td> Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-266929 Share on other sites More sharing options...
kemper Posted June 2, 2007 Author Share Posted June 2, 2007 Tht did not work since Date and Time are different fields within my database. I only need formatting of my time field: `time` time NOT NULL default '00:00:00' I also only want the Time edittable by my associates, thus why Date and Time are separate fields. That code read the time from Date field. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-266939 Share on other sites More sharing options...
per1os Posted June 2, 2007 Share Posted June 2, 2007 h:i a <?php <p style='margin-top: 0; margin-bottom: 0'>'".date("h:i a",strtotime($time['time']))."'</td> ?> Try that. Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-266945 Share on other sites More sharing options...
kemper Posted June 2, 2007 Author Share Posted June 2, 2007 All I get is 12:00 am for any record. Even for records that have times of 08:30:00, they display as 12:00 am. Something doesn't seem right. Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-266958 Share on other sites More sharing options...
Dragen Posted June 2, 2007 Share Posted June 2, 2007 I believe the mysql time field only allows the hous and minutes and not the am/pm part. You'd have to save it as the correct time in the database (without am/pm) then add the am/pm with an if statement when outputting.. something like: <?php $time = explode(':', $data['time']); if($time[0] >= '12' && $time[0] < '00'){ echo 'pm'; }else{ echo 'am'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-266960 Share on other sites More sharing options...
per1os Posted June 2, 2007 Share Posted June 2, 2007 a half assed way of doing it but this should work: http://us2.php.net/manual/en/function.mktime.php //int mktime ( [int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst]]]]]]] ) <?php $time = split(":", $data['time']); $new_time = mktime($time[0], $time[1], $time[2], 1, 1, 1999); echo "<p style='margin-top: 0; margin-bottom: 0'>'".date("h:i a", $new_time)."'</td>"; ?> un-tested but should work. Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-266961 Share on other sites More sharing options...
kemper Posted June 2, 2007 Author Share Posted June 2, 2007 Im still getting 12:00 am. I may just have to stick with the 08:30:00 military time and advise my associates to input as military time. Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-266968 Share on other sites More sharing options...
per1os Posted June 2, 2007 Share Posted June 2, 2007 I do not see why it is not working I just tested it: <?php //int mktime ( [int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst]]]]]]] ) $time = split(":", "08:30:00"); print_R($time); $new_time = mktime($time[0], $time[1], $time[2], 1, 1, 1999); echo "<p style='margin-top: 0; margin-bottom: 0'>'".date("h:i a", $new_time)."'</td>"; //int mktime ( [int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst]]]]]]] ) $time = split(":", "23:30:00"); print_R($time); $new_time = mktime($time[0], $time[1], $time[2], 1, 1, 1999); echo "<p style='margin-top: 0; margin-bottom: 0'>'".date("h:i a", $new_time)."'</td>"; ?> Output: Array ( [0] => 08 [1] => 30 [2] => 00 ) <p style='margin-top: 0; margin-bottom: 0'>'08:30 am'</td> Array ( [0] => 23 [1] => 30 [2] => 00 ) <p style='margin-top: 0; margin-bottom: 0'>'11:30 pm'</td> Are you sure the $time['time'] is coming out of the database right ??? Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-266972 Share on other sites More sharing options...
kemper Posted June 2, 2007 Author Share Posted June 2, 2007 Dragen- mysql is only allowing ##:##:## as HH:MM:SS. I am trying to have that display in a different format as HH:MM am/pm. Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-266973 Share on other sites More sharing options...
kemper Posted June 2, 2007 Author Share Posted June 2, 2007 My original statement was: <p style='margin-top: 0; margin-bottom: 0'>".$data['time']."</td> So, I am confused when you have statements including ... $time['time'] ... And, the '".<b>date</b>("h:i a", $new_time)."' confuses me since it is not a date field. This is all new to me. Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-266975 Share on other sites More sharing options...
per1os Posted June 2, 2007 Share Posted June 2, 2007 Sorry, someoen else posted it in code I used. <?php //int mktime ( [int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst]]]]]]] ) $time = split(":", $data['time']); $new_time = mktime($time[0], $time[1], $time[2], 1, 1, 1999); echo "<p style='margin-top: 0; margin-bottom: 0'>'".date("h:i a", $new_time)."'</td>"; ?> Try that out. I would of hoped you might of been able to figure out how to modify it, but sometimes hoping is too much I guess. Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-266976 Share on other sites More sharing options...
kemper Posted June 2, 2007 Author Share Posted June 2, 2007 It sure appears as though it is pulling from the Date field since it still appears as 12:00 am and the mysql date field is set up as: `date` date NOT NULL default '0000-00-00', Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-266983 Share on other sites More sharing options...
per1os Posted June 2, 2007 Share Posted June 2, 2007 the 12:00 am is the default field. print $data['time'] and post back what it prints out. Because I know the snippet I posted works as I tried it multiple times on my server. Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-266986 Share on other sites More sharing options...
kemper Posted June 2, 2007 Author Share Posted June 2, 2007 Im not sure what you are asking me to do. Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-267008 Share on other sites More sharing options...
chocopi Posted June 2, 2007 Share Posted June 2, 2007 He is telling you to put print $data['time']; into your code and then post what this outputs. That way they can help Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-267009 Share on other sites More sharing options...
kemper Posted June 2, 2007 Author Share Posted June 2, 2007 I tried to and got errors all over the place. Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-267013 Share on other sites More sharing options...
chocopi Posted June 2, 2007 Share Posted June 2, 2007 well post all the errors Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-267014 Share on other sites More sharing options...
kemper Posted June 2, 2007 Author Share Posted June 2, 2007 prolly coding (user) error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/kemper/public_html/***/scheduling.php on line 30 Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-267016 Share on other sites More sharing options...
chocopi Posted June 2, 2007 Share Posted June 2, 2007 can you post line 30 and lines around it Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-267018 Share on other sites More sharing options...
kemper Posted June 2, 2007 Author Share Posted June 2, 2007 OK, I changed it and received: Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/kemper/public_html/***/scheduling.php on line 29 Parse error: syntax error, unexpected T_STRING in /home/kemper/public_html/***/scheduling.php on line 29 Code is: opentable ("Fall Schedules"); print $data['time']\n; closetable (); } Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-267022 Share on other sites More sharing options...
chocopi Posted June 2, 2007 Share Posted June 2, 2007 try changing this: opentable ("Fall Schedules"); print $data['time']\n; closetable (); } to this: opentable ("Fall Schedules"); print ("$data['time']\n"); closetable (); } Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-267025 Share on other sites More sharing options...
kemper Posted June 2, 2007 Author Share Posted June 2, 2007 Received: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/kemper/public_html/***/scheduling.php on line 29 Quote Link to comment https://forums.phpfreaks.com/topic/53993-solved-time-formatting/#findComment-267026 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.