arrayGen Posted January 4, 2011 Share Posted January 4, 2011 Hi all What is the best way to work with times that are stored without there date but with only one date field regarding both times? Thanks Link to comment https://forums.phpfreaks.com/topic/223330-working-with-times-stored-with-one-separate-date/ Share on other sites More sharing options...
BLaZuRE Posted January 4, 2011 Share Posted January 4, 2011 I'd go with a unix timestamp or a DateTime class. Link to comment https://forums.phpfreaks.com/topic/223330-working-with-times-stored-with-one-separate-date/#findComment-1154482 Share on other sites More sharing options...
arrayGen Posted January 4, 2011 Author Share Posted January 4, 2011 I'd go with a unix timestamp or a DateTime class. would this resolve the issues ? that this method of storage causes ? Link to comment https://forums.phpfreaks.com/topic/223330-working-with-times-stored-with-one-separate-date/#findComment-1154759 Share on other sites More sharing options...
Pikachu2000 Posted January 4, 2011 Share Posted January 4, 2011 Why would you store a time without the corresponding date? Link to comment https://forums.phpfreaks.com/topic/223330-working-with-times-stored-with-one-separate-date/#findComment-1154763 Share on other sites More sharing options...
arrayGen Posted January 4, 2011 Author Share Posted January 4, 2011 Why would you store a time without the corresponding date? Its a standardised format requested by a MASSIVE corporation from other MASSIVE cooperation's. Link to comment https://forums.phpfreaks.com/topic/223330-working-with-times-stored-with-one-separate-date/#findComment-1154764 Share on other sites More sharing options...
PFMaBiSmAd Posted January 4, 2011 Share Posted January 4, 2011 It would probably be helpful if you posted what data you do have and what result you are trying to accomplish. It sounds like a date and two times per row? What format is the date and what format is the time? Link to comment https://forums.phpfreaks.com/topic/223330-working-with-times-stored-with-one-separate-date/#findComment-1154765 Share on other sites More sharing options...
arrayGen Posted January 4, 2011 Author Share Posted January 4, 2011 It would probably be helpful if you posted what data you do have and what result you are trying to accomplish. It sounds like a date and two times per row? What format is the date and what format is the time? the super twats from the super companies all use start: 11::00:00 end: 00:00:00 date: 2011-01-01 you can see the apparent failure here. ??? can you ? Link to comment https://forums.phpfreaks.com/topic/223330-working-with-times-stored-with-one-separate-date/#findComment-1154768 Share on other sites More sharing options...
arrayGen Posted January 4, 2011 Author Share Posted January 4, 2011 please tell me you see it Link to comment https://forums.phpfreaks.com/topic/223330-working-with-times-stored-with-one-separate-date/#findComment-1154771 Share on other sites More sharing options...
Psycho Posted January 4, 2011 Share Posted January 4, 2011 the super twats from the super companies all use start: 11::00:00 end: 00:00:00 date: 2011-01-01 you can see the apparent failure here. ??? can you ? I don't think you should be throwing derogatory names around like that. Because as arrayGen just alluded to, it seems YOU are the only one that doesn't see the obvious solution: Combine the date with each time - individually - to come up with two timestamps! Although your example is in error since the end time is before the start time. 00:00:00 is the beginning of a day not the end of a day. So, in reality your two timestamps should be Start timestamp: 2011-01-01 11:00:00 End timestamp: 2011-02-01 00:00:00 Link to comment https://forums.phpfreaks.com/topic/223330-working-with-times-stored-with-one-separate-date/#findComment-1154779 Share on other sites More sharing options...
arrayGen Posted January 4, 2011 Author Share Posted January 4, 2011 the super twats from the super companies all use start: 11::00:00 end: 00:00:00 date: 2011-01-01 you can see the apparent failure here. ??? can you ? I don't think you should be throwing derogatory names around like that. Because as arrayGen just alluded to, it seems YOU are the only one that doesn't see the obvious solution: Combine the date with each time - individually - to come up with two timestamps! Although your example is in error since the end time is before the start time. 00:00:00 is the beginning of a day not the end of a day. So, in reality your two timestamps should be Start timestamp: 2011-01-01 11:00:00 End timestamp: 2011-02-01 00:00:00 yes Sherlock, but what im trying to say is, the times are stored as start: 11::00:00 end: 00:00:00 date: 2011-01-01 but how would you manipulate this to correct it ? strtotime(date("Y-m-d H:i:s", "{end} {date}")) - strtotime(date("Y-m-d H:i:s", "{start} {date}")) will cause a minus time , this is true but how do we rectify this what would be the best angle of attack. Link to comment https://forums.phpfreaks.com/topic/223330-working-with-times-stored-with-one-separate-date/#findComment-1154780 Share on other sites More sharing options...
Psycho Posted January 4, 2011 Share Posted January 4, 2011 Why do you see the need to resort to name calling? What was not clear in the previous posts was that the end time may - intentionally - be less than the start time. If that is the case, then I would assume that the end time is for the next day. So the solution is simple. If the end time is before the start time, then increment the end date to +1 days. $start_time = "11:00:00"; $end_time = "00:00:00"; $date = "2011-01-01"; $start_timestamp = strtotime("{$date} {$start_time}"); $end_timestamp = strtotime("{$date} {$end_time}"); //Check if end time is before start time if($end_timestamp < $start_timestamp) { //Adjust end date to next day $end_timestamp = strtotime("{$date} {$end_time} +1 days"); } echo "Start date/time: " . date('m-d-Y H:i:s', $start_timestamp); echo "<br />End date/time: " . date('m-d-Y H:i:s', $end_timestamp); //Output //Start date/time: 01-01-2011 11:00:00 //End date/time: 01-02-2011 01:00:00 Link to comment https://forums.phpfreaks.com/topic/223330-working-with-times-stored-with-one-separate-date/#findComment-1154843 Share on other sites More sharing options...
arrayGen Posted January 4, 2011 Author Share Posted January 4, 2011 Why do you see the need to resort to name calling? What was not clear in the previous posts was that the end time may - intentionally - be less than the start time. If that is the case, then I would assume that the end time is for the next day. So the solution is simple. If the end time is before the start time, then increment the end date to +1 days. $start_time = "11:00:00"; $end_time = "00:00:00"; $date = "2011-01-01"; $start_timestamp = strtotime("{$date} {$start_time}"); $end_timestamp = strtotime("{$date} {$end_time}"); //Check if end time is before start time if($end_timestamp < $start_timestamp) { //Adjust end date to next day $end_timestamp = strtotime("{$date} {$end_time} +1 days"); } echo "Start date/time: " . date('m-d-Y H:i:s', $start_timestamp); echo "<br />End date/time: " . date('m-d-Y H:i:s', $end_timestamp); //Output //Start date/time: 01-01-2011 11:00:00 //End date/time: 01-02-2011 01:00:00 your still unsure, mr self proclaimed guru, who invented guru ? and mogul ? Link to comment https://forums.phpfreaks.com/topic/223330-working-with-times-stored-with-one-separate-date/#findComment-1154848 Share on other sites More sharing options...
arrayGen Posted January 4, 2011 Author Share Posted January 4, 2011 Why do you see the need to resort to name calling? What was not clear in the previous posts was that the end time may - intentionally - be less than the start time. If that is the case, then I would assume that the end time is for the next day. So the solution is simple. If the end time is before the start time, then increment the end date to +1 days. $start_time = "11:00:00"; $end_time = "00:00:00"; $date = "2011-01-01"; $start_timestamp = strtotime("{$date} {$start_time}"); $end_timestamp = strtotime("{$date} {$end_time}"); //Check if end time is before start time if($end_timestamp < $start_timestamp) { //Adjust end date to next day $end_timestamp = strtotime("{$date} {$end_time} +1 days"); } echo "Start date/time: " . date('m-d-Y H:i:s', $start_timestamp); echo "<br />End date/time: " . date('m-d-Y H:i:s', $end_timestamp); //Output //Start date/time: 01-01-2011 11:00:00 //End date/time: 01-02-2011 01:00:00 your still unsure, mr self proclaimed guru, who invented guru ? and mogul ? what layer of the application would you tackle this problem in ? only an idiot would do it like that Link to comment https://forums.phpfreaks.com/topic/223330-working-with-times-stored-with-one-separate-date/#findComment-1154857 Share on other sites More sharing options...
Psycho Posted January 4, 2011 Share Posted January 4, 2011 what layer of the application would you tackle this problem in ? only an idiot would do it like that You did post this in the PHP forum, right? So it is only logical that you were looking for a PHP solution. If you wanted a database or other type of solution you should post in the appropriate forum. Link to comment https://forums.phpfreaks.com/topic/223330-working-with-times-stored-with-one-separate-date/#findComment-1154868 Share on other sites More sharing options...
arrayGen Posted January 4, 2011 Author Share Posted January 4, 2011 what layer of the application would you tackle this problem in ? only an idiot would do it like that You did post this in the PHP forum, right? So it is only logical that you were looking for a PHP solution. If you wanted a database or other type of solution you should post in the appropriate forum. not too sharp today are we Jaldinder Gee Link to comment https://forums.phpfreaks.com/topic/223330-working-with-times-stored-with-one-separate-date/#findComment-1154870 Share on other sites More sharing options...
MatthewJ Posted January 4, 2011 Share Posted January 4, 2011 So is your theory for the best way to get help to be a jerk? You're here looking for a solution to what is frankly a simple problem, and though you didn't have enough programming acumen to solve the issue yourself, you're bright enough to critique the code? Classic Link to comment https://forums.phpfreaks.com/topic/223330-working-with-times-stored-with-one-separate-date/#findComment-1154873 Share on other sites More sharing options...
arrayGen Posted January 4, 2011 Author Share Posted January 4, 2011 So is your theory for the best way to get help to be a jerk? You're here looking for a solution to what is frankly a simple problem, and though you didn't have enough programming acumen to solve the issue yourself, you're bright enough to critique the code? Classic i solved it way before you guys did, your slow as hell. Link to comment https://forums.phpfreaks.com/topic/223330-working-with-times-stored-with-one-separate-date/#findComment-1154881 Share on other sites More sharing options...
Pikachu2000 Posted January 4, 2011 Share Posted January 4, 2011 That's about enough. Thread locked. Link to comment https://forums.phpfreaks.com/topic/223330-working-with-times-stored-with-one-separate-date/#findComment-1154884 Share on other sites More sharing options...
Recommended Posts