home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a012 / 1.ddi / CHAP21.EXE / CHP2118.PRG < prev    next >
Encoding:
Text File  |  1991-04-30  |  2.1 KB  |  91 lines

  1. /*
  2.    Listing 21.18  DATE/TIME functions
  3.    Author: Joe Booth
  4.    Excerpted from "Clipper 5: A Developer's Guide"
  5.    Copyright (c) 1991 M&T Books
  6.                       501 Galveston Drive
  7.                       Redwood City, CA 94063-4728
  8.                       (415) 366-3600
  9. */
  10.  
  11. //───── NOTE: must compile with the /N option!
  12.  
  13. STATIC basedate := "01/01/80"
  14. STATIC half_day := 43200
  15.  
  16. function datetime(dVar,cTime)
  17. LOCAL nDatetime := -1, nSeconds:=0
  18. LOCAL cDate, cSeconds
  19. if dVar=NIL .OR. cTime=NIL
  20.    return -1
  21. else
  22.    cDate     := alltrim(str(dVar-ctod(basedate),12,0))
  23.    nSeconds  := val(cTime)*3600 + val(substr(cTime,4,2))*60 +val(substr(cTime,7,2))
  24.    cSeconds  := alltrim(str(nSeconds))
  25.    nDatetime := val(cDate+"."+cSeconds)
  26. endif
  27. return nDatetime
  28.  
  29.  
  30. function getdate(nDatetime)
  31. LOCAL dDate := ctod("")
  32. if nDatetime<>NIL
  33.    dDate := ctod(basedate) + int(nDatetime)
  34. endif
  35. return dDate
  36.  
  37.  
  38. function gettime(nDatetime)
  39. LOCAL cTemp := str(nDatetime,15,5)
  40. LOCAL nSecs := val(substr(cTemp,11,5))
  41. cTemp := str(Sec2hours(nSecs),5,2)
  42. return strtran(cTemp,".",":")+":00"
  43.  
  44.  
  45. function elap_days(nDt1,nDt2)
  46. LOCAL nDays :=-1, nDiff
  47. if nDt1=NIL .or. nDt2=NIL
  48.    return -1
  49. else
  50.    nDiff := abs( nDt1-nDt2 )
  51.    nDays := int(nDiff)
  52.    if nDiff - nDays >  half_day
  53.       nDays ++
  54.    endif
  55. endif
  56. return nDays
  57.  
  58.  
  59. function elap_hours(nDt1,nDt2)
  60. LOCAL nHours :=-1,nDiff:=0,nRest:=0,nSecs:=0
  61. if nDt1=NIL .or. nDt2=NIL
  62.    return -1
  63. else
  64.    nDiff  := abs( nDt1-nDt2 )
  65.    nHours := int(nDiff) * 24      // Number of days * 24 hours
  66.    nSecs  := val(substr(str(nDiff,15,5),11,5))
  67.    nHours := nHours + (nSecs/3600)
  68.    if nSecs % 3600 > 1800
  69.       nHours++
  70.    endif
  71. endif
  72. return nHours
  73.  
  74.  
  75. function elap_mins(nDt1,nDt2)
  76. LOCAL nMins :=-1,nDiff:=0,nRest:=0,nSecs:=0
  77. if nDt1=NIL .or. nDt2=NIL
  78.    return -1
  79. else
  80.    nDiff  := abs( nDt1-nDt2 )
  81.    nMins  := int(nDiff) * 1440    // Number of days expressed in minutes
  82.    nSecs  := val(substr(str(nDiff,15,5),11,5))
  83.    nMins  := nMins + (nSecs/60)
  84.    if nSecs % 60 > 30
  85.       nMins++
  86.    endif
  87. endif
  88. return nMins
  89.  
  90. // end of file CHP2118.PRG
  91.