home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 21.18 DATE/TIME functions
- Author: Joe Booth
- Excerpted from "Clipper 5: A Developer's Guide"
- Copyright (c) 1991 M&T Books
- 501 Galveston Drive
- Redwood City, CA 94063-4728
- (415) 366-3600
- */
-
- //───── NOTE: must compile with the /N option!
-
- STATIC basedate := "01/01/80"
- STATIC half_day := 43200
-
- function datetime(dVar,cTime)
- LOCAL nDatetime := -1, nSeconds:=0
- LOCAL cDate, cSeconds
- if dVar=NIL .OR. cTime=NIL
- return -1
- else
- cDate := alltrim(str(dVar-ctod(basedate),12,0))
- nSeconds := val(cTime)*3600 + val(substr(cTime,4,2))*60 +val(substr(cTime,7,2))
- cSeconds := alltrim(str(nSeconds))
- nDatetime := val(cDate+"."+cSeconds)
- endif
- return nDatetime
-
-
- function getdate(nDatetime)
- LOCAL dDate := ctod("")
- if nDatetime<>NIL
- dDate := ctod(basedate) + int(nDatetime)
- endif
- return dDate
-
-
- function gettime(nDatetime)
- LOCAL cTemp := str(nDatetime,15,5)
- LOCAL nSecs := val(substr(cTemp,11,5))
- cTemp := str(Sec2hours(nSecs),5,2)
- return strtran(cTemp,".",":")+":00"
-
-
- function elap_days(nDt1,nDt2)
- LOCAL nDays :=-1, nDiff
- if nDt1=NIL .or. nDt2=NIL
- return -1
- else
- nDiff := abs( nDt1-nDt2 )
- nDays := int(nDiff)
- if nDiff - nDays > half_day
- nDays ++
- endif
- endif
- return nDays
-
-
- function elap_hours(nDt1,nDt2)
- LOCAL nHours :=-1,nDiff:=0,nRest:=0,nSecs:=0
- if nDt1=NIL .or. nDt2=NIL
- return -1
- else
- nDiff := abs( nDt1-nDt2 )
- nHours := int(nDiff) * 24 // Number of days * 24 hours
- nSecs := val(substr(str(nDiff,15,5),11,5))
- nHours := nHours + (nSecs/3600)
- if nSecs % 3600 > 1800
- nHours++
- endif
- endif
- return nHours
-
-
- function elap_mins(nDt1,nDt2)
- LOCAL nMins :=-1,nDiff:=0,nRest:=0,nSecs:=0
- if nDt1=NIL .or. nDt2=NIL
- return -1
- else
- nDiff := abs( nDt1-nDt2 )
- nMins := int(nDiff) * 1440 // Number of days expressed in minutes
- nSecs := val(substr(str(nDiff,15,5),11,5))
- nMins := nMins + (nSecs/60)
- if nSecs % 60 > 30
- nMins++
- endif
- endif
- return nMins
-
- // end of file CHP2118.PRG
-