SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,209
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    calculating time

    Code:
    <cfif not isDefined('session.time')>
       <cfset session.time=timeformat(now(),'HHmmss')>
    </cfif>
    
    <cfset variables.time=timeformat(now(),'HHmmss')>
    I like to calculate passing time, i.e., variables.time minus session.time.
    As one minute has 60 seconds instead of 100 seconds, calculating time is hard.


    Code:
    <cfoutput>
    <cfif left(variables.time,2) lt left(session.time,2)>
    
      <cfif right(left(variables.time,4),2) lt right(left(session.time,4),2)>
        #left(variables.time,2)-left(session.time,2)-1+23# :
      <cfelse>
        #left(variables.time,2)-left(session.time,2)+24# :
      </cfif>
    
    <cfelse>
    
      <cfif right(left(variables.time,4),2) lt right(left(session.time,4),2)>
        #left(variables.time,2)-left(session.time,2)-1# :
      <cfelse>
        #left(variables.time,2)-left(session.time,2)# :
      </cfif>
    
    </cfif>
    
    
    <cfif right(left(variables.time,4),2) lt right(left(session.time,4),2)>
    
      <cfif right(variables.time,2) lt right(session.time,2)>
        #right(left(variables.time,4),2)-right(left(session.time,4),2)+59#
      <cfelse>
        #right(left(variables.time,4),2)-right(left(session.time,4),2)+60#
      </cfif>
    
    <cfelse>
    
      <cfif right(variables.time,2) lt right(session.time,2)>
        #right(left(variables.time,4),2)-right(left(session.time,4),2)-1#
      <cfelse>
        #right(left(variables.time,4),2)-right(left(session.time,4),2)#
      </cfif>
    
    </cfif>
    
     
    
    
    <cfif right(variables.time,2) lt right(session.time,2)>
      #right(variables.time,2)-right(session.time,2)+60#
    <cfelse>
      #right(variables.time,2)-right(session.time,2)#
    </cfif>
    </cfoutput>
    The code above is too long, but I guess it works.

    Do you have any simple one?
    Last edited by dotJoon; Nov 9, 2008 at 07:09.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,016
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    DateDiff("s",variables.time,session.time) gives the difference in seconds
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •