tekrscom Posted March 25, 2010 Share Posted March 25, 2010 Hey Everybody... PHP Version 5.2.13 I'm merely trying to get the Hours and Minutes from a MySQL DateTime field... and I'm having serious issues doing it... I was able to pull the whole time by using this code... $arrTimeToStart = explode(" ", $row['WorkOrderDateTimeToStart']); $arrTimeToComplete = explode(" ", $row['WorkOrderDateTimeToComplete']); But I need the Hours separately from the Minutes... So I tried this... But it doesn't work... $WorkOrderDateTimeToStart = getdate(date($row['WorkOrderDateTimeToStart'])); $WorkOrderDateTimeToComplete = getdate(date($row['WorkOrderDateTimeToComplete'])); $HoursToStart = $WorkOrderDateTimeToStart[hours]; $MinutesToStart = $WorkOrderDateTimeToStart[minutes]; $HoursToComplete = $WorkOrderDateTimeToComplete[hours]; $MinutesToComplete = $WorkOrderDateTimeToComplete[minutes]; if ($HoursToStart > 12) { $HoursToStart -= 12; $AMorPMtoStart = 'PM'; } else { $AMorPMtoStart = 'AM'; } if ($HoursToComplete > 12) { $HoursToStart -= 12; $AMorPMtoComplete = 'PM'; } else { $AMorPMtoComplete = 'AM'; } Here's the implementation code:... <td> <select name="HourToStart" style="width: 50px;">'; for($i=0;$i<13;$i++) { echo '<option value="'.sprintf("%02d",$i).'"'; if ($HoursToStart == sprintf("%02d",$i)) {echo ' selected';} echo '>'.sprintf("%02d",$i).'</option>'; } echo '</select> </td> <td> <select name="MinutesToStart" style="width: 50px;">'; for($i=0;$i<60;$i++) { echo '<option value="'.sprintf("%02d",$i).'"'; if ($MinutesToStart == sprintf("%02d",$i)) {echo ' selected';} echo '>'.sprintf("%02d",$i).'</option>'; } echo '</select> </td> <td> <select name="AMorPMtoStart" style="width: 50px;"> <option value="AM"'; if ($AMorPMtoStart == 'AM') {echo ' selected';} echo '>AM</option> <option value="PM"'; if ($AMorPMtoStart == 'PM') {echo ' selected';} echo '>PM</option> </select> </td> Here's the error I get... "Warning: getdate() expects parameter 1 to be long" Can anybody help me figure this out, it's driving me bonkers Link to comment https://forums.phpfreaks.com/topic/196500-date-time-issues/ Share on other sites More sharing options...
andrewgauger Posted March 25, 2010 Share Posted March 25, 2010 I think you want to do $WorkOrderDateTimeToStart=getdate(strtotime($row['WorkOrderDateTimeToStart'])); Link to comment https://forums.phpfreaks.com/topic/196500-date-time-issues/#findComment-1031694 Share on other sites More sharing options...
tekrscom Posted March 25, 2010 Author Share Posted March 25, 2010 Well, that took away the error,... but the information it gives doesn't coincide with what's in the database... Here is the result of the DateTime field in the MySQL database... 2010-03-26 03:15:00 ... Notice the Hour is 03 ... the result with your solution gives 18 and notice the Minutes are 15 ... but the result gives 0 Link to comment https://forums.phpfreaks.com/topic/196500-date-time-issues/#findComment-1031703 Share on other sites More sharing options...
andrewgauger Posted March 25, 2010 Share Posted March 25, 2010 Do a print_r on $WorkOrderDateTimeToStart and $WorkOrderDateTimeToComplete and see if the date looks ok. I speculate you have the wrong $row Link to comment https://forums.phpfreaks.com/topic/196500-date-time-issues/#findComment-1031723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.