-1
$\begingroup$

I need to calculate the difference between two dates in hours and in minutes which is what the code below does. The only issue I have is that the dates and the location (timezone) has to be input by the user. How do I achieve that? Can be a different language from PHP as I only need a flowchart and the pseudocode.

?php

$departure = new DateTime('8pm March 27, 2016 America/New_York');

$arrival = new DateTime('7:20am March 28, 2016 Europe/London');

$flighttime = $departure->diff($arrival);

echo "$flighttime-> h hours $flight_time->i minutes";

Output: 7 hours 20 minutes

$\endgroup$

closed as off-topic by Karolis Juodelė, Evil, David Richerby, Juho, Rick Decker Nov 27 '16 at 21:11

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about software development or programming tools are off-topic here, but can be asked on Stack Overflow." – Karolis Juodelė, Evil, David Richerby, Juho, Rick Decker
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ What's the problem exactly? That the '8pm March 27, 2016 America/New_York' string comes from user input? Are you asking how to validate it? $\endgroup$ – Karolis Juodelė Nov 22 '16 at 14:24
  • $\begingroup$ $departure = new DateTime('8pm March 27, 2016 America/New_York'); Inside of the bracket, I need that to be the user input, so the user inputs that information. $\endgroup$ – James Nov 22 '16 at 14:44
  • $\begingroup$ So you're asking how to take a string from a some textarea in some html and run your code on it? $\endgroup$ – Karolis Juodelė Nov 22 '16 at 14:59
  • $\begingroup$ Yes, I want the user to input the date and the location from which the timezone is taken and then run the code on it to calculate the difference between the two inputted dates. $\endgroup$ – James Nov 22 '16 at 15:05
  • 2
    $\begingroup$ You're asking for an algorithm but this is something for which you should use your programming environment's built-in date and time handling routines, rather than trying to roll your own code. This is the sort of thing where reinventing the wheel just causes mistakes from obscure cases. $\endgroup$ – David Richerby Nov 22 '16 at 16:25
1
$\begingroup$

TimeA -> ConvertToTimeZoneUtc -> NormalizeToGreenwichUtcTime -> ConvertToTicks Same for timeB ( ticksA - tickB) => timepsan. GetHours | GetMins

Is that ok?

$\endgroup$
  • 2
    $\begingroup$ Welcome to Computer Science! It seems like a good idea converting to one format and make calculations there but a textual description would be nice and please make sure that question is on-topic and not a duplicate before providing an answer. $\endgroup$ – Evil Nov 22 '16 at 19:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.