Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.clipper.visual-objects > #5322
| From | "Arne Ortlinghaus" <Arne.Ortlinghaus@acs.it> |
|---|---|
| Newsgroups | comp.lang.clipper.visual-objects |
| Subject | Re: Compare date+hour |
| Date | 2013-06-04 18:05 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <kol2vp$ofd$1@dont-email.me> (permalink) |
| References | <398c6d2a-40da-41ed-907a-fcf31b8203e5@googlegroups.com> |
I use always the SQL date time string format of the form YYYY-MM-DD HH:MM:SS
Below are some conversion functions.
Arne Ortlinghaus
ACS Data Systems
function MakeTimeStampBase(dDate, nSeconds )
//p Erzeugen eines Timestamps aus Datum und Sekunden
//a dDate - Datum
//a nSeconds - Int Sekunden seit Mitternacht
//d Wenn nSeconds < 0, wird dDate um eins verkleinert und nSeconds
hochgezählt
//r Timestamp ODBC-Format (formattierter String 19 Zeichen)
local cTimestamp as string
local wHours as word
local wMinutes as word
local cFrac as string
local cTime as string
if IsNil(dDate)
dDate := Today()
endif
if IsNil (nSeconds)
nSeconds := 0 // gibt sonst Probleme mit Offene Posten in Radix
endif
while nSeconds < 0
dDate := dDate-1
nSeconds += 86400
enddo
cFrac := LTrim(__Str( Frac( nSeconds ) ))
cFrac := SubStr2( cFrac, At2( ".", cFrac ) + 1 )
cFrac := PadR( cFrac, 9, "0" )
nSeconds := Integer( nSeconds )
wHours := Integer( nSeconds / 3600 )
nSeconds := MOD( nSeconds, 3600 )
wMinutes := Integer( nSeconds / 60 )
nSeconds := MOD( nSeconds, 60 )
cTime := StrZero( wHours, 2, 0 ) + ":" + ;
StrZero( wMinutes, 2, 0 ) + ":" + ;
StrZero( nSeconds, 2, 0 ) + "." + ;
cFrac
cTimestamp := Left(DToCSQLBase( dDate ) + " " + cTime, 19)
return cTimeStamp
func DToCSQLBase ( dDate as date ) as
string
local nDay as usual // usual wegen Problemen mit StrZero
local nMonth as usual
local nYear as usual
nDay := Day(dDate)
nMonth := Month(dDate)
nYear := Year(dDate)
return Str(nYear, 4) +"-" + StrZero (nMonth, 2)+"-"+ StrZero (nDay, 2)
func TimeStampAddTime (cT, nAddDays, nAddSeconds)
//p Addieren/Subtrahieren Monate
//a cT - Timestamp-String
//a nAdddays - Int: Anzahl Tage dazu (Negative weg)
//a nAddSeconds - Int: Anzahl Sekunden dazu (Negative weg)
//r Timestamp
local a as array
local d as date
local nSeconds as int
if Empty(cT)
return cT
endif
a := TimeStampToDateandTime (cT)
d := a[1]
nSeconds := a[2]
if !Empty(nAddDays)
d += nAddDays
endif
if !Empty(nAddSeconds)
nSeconds += nAddSeconds
endif
do while nSeconds >= 86400
nSeconds -= 86400
d += 1
enddo
do while nSeconds < 0
nSeconds += 86400
d -= 1
enddo
return MakeTimeStampBase(d, nSeconds)
function TimeStampDifference(cT1, cT2, nFormat)
//p Differenz von zwei Zeiten cT1-cT2
//a cT1 - String: Timestamp
//a cT2 - String: Timestamp
//a nFormat - Int: 2: Datum, 3: Zeit in Minuten, 4: Zeit in Sekunden
local a2, a1 as array
local nSec as int
a1 := TimeStampToDateandTime (cT1)
a2 := TimeStampToDateandTime (cT2)
if nFormat == 2
return a1[1] - a2[1]
endif
nSec := a1[2] - a2[2]
do while a1[1] > a2[1]
a1[1] := a1[1]-1
nSec += 86400
enddo
do while a1[1] < a2[1]
a1[1] := a1[1]+1
nSec -= 86400
enddo
if nFormat == 3
return nSec / 60
elseif nFormat == 4
return nSec
else
MsgInternalError("TimeStampDifference - Wrong Format: " +
Typevalue2String(nFormat))
return 0
endif
function TimeStampToDateandTime (cTimeStamp)
//p Aufteilen eines Timestamps in Datum und Zeit
//a Timestamp ODBC-Format (formattierter String 19 Zeichen)
//r Array: {dDate - Datum, nSeconds - Int Sekunden seit Mitternacht}
local dDate as date
local nSeconds as int
dDate := CToDAnsi(cTimeStamp)
cTimeStamp := SubStr(cTimeStamp, 12)
nSeconds := Val(SubStr(cTimeStamp, 1, 2)) * 3600
nSeconds += Val(SubStr(cTimeStamp, 4, 2)) * 60
nSeconds += Val(SubStr(cTimeStamp, 7, 2))
return {dDate, nSeconds}
Back to comp.lang.clipper.visual-objects | Previous | Next — Previous in thread | Find similar | Unroll thread
Compare date+hour Paulo Oliveira <paulo@clipinfor.com> - 2013-06-04 07:29 -0700 Re: Compare date+hour Pilks <richardp@lukhozi.co.za> - 2013-06-04 07:52 -0700 Re: Compare date+hour "Wolfgang Riedmann" <wriedmann@gmail.com> - 2013-06-04 17:57 +0200 Re: Compare date+hour "Arne Ortlinghaus" <Arne.Ortlinghaus@acs.it> - 2013-06-04 18:05 +0200
csiph-web