Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
New Visual FreePro time/timing functions
Message
From
05/10/2013 16:37:21
 
 
To
05/10/2013 16:35:34
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01584822
Message ID:
01584823
Views:
70
> Visual FreePro adds two new variable types, and several new functions:
> SECONDSX() a SECONDS() like functions with resolutions down to nearly 0.00002 seconds.
> DATETIMEX() a 64-bit integer value operating at the CPU clock speed (3.3 GHz machine, 3.3 billion ticks per second)
> DATESECONDS() a DATETIME() like function which stores DATE() plus SECONDS() in a single 8-byte quantity
> DATESECONDSX() a DATEIME() like function which stores DATE() plus SECONDSX() in a single 8-byte quantity


These new Visual FreePro functions will allow high resolution timing computations without the need to pass more than two parameters, as is required today as with this timeBetween() function:
* Rick C. Hodgin born at approximately 4:35am, 08/10/1969
ldStart = CTOD("08/10/1969")
lnStart = (4*60*60) + (35*60) 

* How old is Rick C. Hodgin now?
? "Rick C. Hodgin is approximately this old:"
? timeBetween(ldStart, lnStart, DATE(), SECONDS())


**********
* Note:  You can also directly obtain the individual elements using:
*STORE 0 TO lnYears, lnDays, lnHour, lnMinute, lnSecond, lnMillisecond
*? timeBetween(ldStart, lnStart, ldEnd, lnEnd, .F., @lnYears, @lnDays, @lnHour, @lnMinute, @lnSecond, @lnMillisecond)
*? lnYears, lnDays, lnHour, lnMinute, lnSecond, lnMillisecond
**********


**********
* pdStart = DATE() at start
* pnStart = SECONDS() at start
* pdEnd   = DATE() at end
* pnEnd   = SECONDS() at end
* plIncludeAll = Include all fields in output?
*****
FUNCTION timeBetween
LPARAMETERS pdStart, pnStart, pdEnd, pnEnd, plIncludeAll, lnYears, lnDays, lnHour, lnMinute, lnSecond, lnMillisecond
LOCAL lnSeconds
    
    * Compute the total number of seconds
    lnSeconds     = ((pdEnd - pdStart) * (24 * 60 * 60)) + (pnEnd - pnStart)
    
    * Now, you can obtain the minutes by each
    lnYears       = INT(lnSeconds / (365.25 * 24 * 60 * 60))
    lnSeconds     = lnSeconds % (365.25 * 24 * 60 * 60)
    
    lnDays        = INT(lnSeconds / (24 * 60 * 60))
    lnSeconds     = lnSeconds % (24 * 60 * 60)
    
    lnHour        = INT(lnSeconds / (60 * 60))
    lnSeconds     = lnSeconds % (60 * 60)
    llAm          = (lnHour <= 12)
    
    lnMinute      = INT(lnSeconds / 60)
    lnSeconds     = lnSeconds % 60
    
    lnSecond      = INT(lnSeconds)
    lnMillisecond = INT((lnSeconds % 1) * 1000)


    RETURN IIF(plIncludeAll OR lnYears != 0,  TRANSFORM(lnYears)  + " years ",   SPACE(0)) + ;
           IIF(plIncludeAll OR lnDays != 0,   TRANSFORM(lnDays)   + " days ",    SPACE(0)) + ;
           IIF(plIncludeAll OR lnHour != 0,   TRANSFORM(lnHour)   + " hours ",   SPACE(0)) + ;
           IIF(plIncludeAll OR lnMinute != 0, TRANSFORM(lnMinute) + " minutes ", SPACE(0)) + ; 
           IIF(plIncludeAll OR lnSecond != 0, TRANSFORM(lnSecond) + " seconds ", SPACE(0)) + ;
           ALLTRIM(STR(lnMillisecond,3,0)) + " milliseconds"
Previous
Reply
Map
View

Click here to load this message in the networking platform