Jump to content

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);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.