Jump to content

[SOLVED] Difference between user inputted times


smerny

Recommended Posts

I'd like to have a user enter two times (within a single day) and be able to tell the difference between them...

 

I was trying to figure out a way and wanted to check what decimal value a time format string would give, so i did this:

 

$time = "8:30" * 1.0

 

and got "8"? (I was hoping for 8.5)

 

Anyway, what is the best way to do this?

 

- I have an input for start and end times.

- I can assume that if a start time is 8 to 11:59, it is AM

- I can assume that if an end time is 12 to 10, it is PM

I was thinking if I could get them in decimal values, like say 8:30 is start and 6:00 is end... if I could get them to be 8.5 and 6, I could then do something like:

 

if (1 <= $start && $start < 
    $start += 12;
if (1 <= $end && $end < 10)
   $end += 12;

$difference = floor($end - $start) .":". round((($end-$start) - floor($end - $start)) * 60);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.