So what I am trying to do is add two strings together in the form of military time. Here is the example.
Time1 = “01:00”;
Time2 = “04:30”;
Adding the two together would produce “05:30”. This seems incredibly simple, but it has been a long long day for a new learner. Any help would be greatly appreciated.
You can do something like this in PHP 5.3:
Converting 04:30 to PT04H30M should be trivial. Note that whether this is actually what you want depends on what you mean by “04:30”. This code may or may not sum 4*60+30 minutes to the actual time.
If you mean “4 hours and 30 minutes on the clock” this is always correct. However, if you mean “4*60+30 minutes”, it depends on the day and timezone. Example:
An alternate implementation of the last case (assuming current day and default timezone) for PHP 5.2 is
For the first case, we must do: