Wow!  Thanks so much for taking the time to break this down---I think
I've got more than enough info to get started now--Laura

        -----Original Message-----
        From: [email protected]
[mailto:[EMAIL PROTECTED] On Behalf Of Michael Roush
        Sent: Tuesday, August 23, 2005 11:02 AM
        To: [email protected]
        Subject: Re: [php_mysql] Calculating amount of time?
        
        
        --- Laura Solomon <[EMAIL PROTECTED]> wrote:
        
        > How would I go about calculating the amount of time passed
between two
        > inputted times?  For example, how could I calculate how much
time has
        > passed between 10 am and 5 pm?  Assuming that the input is in
standard
        > English time format and I want to end up with a UNIX
timestamp?
        
        Okay, let's start with two different given times:
        8:12:53 AM Aug 23 2005 and 10:42:06 PM Aug 24 2005.
        
        $first_date  = mktime( 8,12,53,8,23,2005);
        $second_date = mktime(22,42,06,8,24,2005);
        $difference = $second_date = $first_date;
        
        $difference is the number of seconds between the two
dates/times.  A UNIX
        timestamp is literally the number of seconds between 1/1/70 and
the given
        date/time, so even though $difference is an integer that looks
like a UNIX
        timestamp, if you format it with the date() function, you're
going to get
        funky results.  Divide $difference by 3600 (60*60) to find out
the number
        of hours.
        
        The mktime() function takes the following format:
        mktime([hour],[minute],[second],[month],[day],[year]);
        
        One thing to watch for is if you are asking for input from the
user, you
        need to be creative with calculating the hour figure based on
the number
        they put in and whether it is AM or PM.  PM hours need to have
12 added to
        them, unless they are "12".  AM hours are as-is, unless they are
"12"
        (which should be changed to "0").  A few "if" statements based
on the
        user's selection of "AM" or "PM" and what their entered hour is
takes care
        of that.
        
        Another potential monkey wrench is DST.  That will never affect
the number
        of hours between 10 AM and 5 PM.  But, there are two days each
year where
        the difference between 10 PM and 5 AM is not 7 hours.  However,
most
        servers with PHP installed handle this change seamlessly, giving
you a 6
        on that accursed day in April and an 8 on that blessed day in
October!
        
        
        
        
        
        Michael Roush
        [EMAIL PROTECTED]
        
        "The power of the Web is in its universality. Access by everyone
regardless of disability is an essential aspect." 
        -- Tim Berners-Lee, W3C Director and inventor of the World Wide
Web
        
        
                    
        ____________________________________________________
        Start your day with Yahoo! - make it your home page 
        http://www.yahoo.com/r/hs 
        
        
        
        The php_mysql group is dedicated to learn more about the
PHP/MySQL web database possibilities through group learning. 
        
        
        
  _____  

        YAHOO! GROUPS LINKS 


                
        *        Visit your group "php_mysql
<http://groups.yahoo.com/group/php_mysql> " on the web.
                  
        *        To unsubscribe from this group, send an email to:
                 [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> 
                  
        *        Your use of Yahoo! Groups is subject to the Yahoo!
Terms of Service <http://docs.yahoo.com/info/terms/> . 


  _____  




[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
<font face=arial size=-1><a 
href="http://us.ard.yahoo.com/SIG=12h6kgh22/M=362131.6882499.7825260.1510227/D=groups/S=1705375618:TM/Y=YAHOO/EXP=1124816672/A=2889191/R=0/SIG=10r90krvo/*http://www.thebeehive.org
">Get Bzzzy! (real tools to help you find a job) Welcome to the Sweet Life 
- brought to you by One Economy</a>.</font>
--------------------------------------------------------------------~-> 

The php_mysql group is dedicated to learn more about the PHP/MySQL web database 
possibilities through group learning.  
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php_mysql/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to