Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #5319 > unrolled thread

Compare date+hour

Started byPaulo Oliveira <paulo@clipinfor.com>
First post2013-06-04 07:29 -0700
Last post2013-06-04 18:05 +0200
Articles 4 — 4 participants

Back to article view | Back to comp.lang.clipper.visual-objects


Contents

  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

#5319 — Compare date+hour

FromPaulo Oliveira <paulo@clipinfor.com>
Date2013-06-04 07:29 -0700
SubjectCompare date+hour
Message-ID<398c6d2a-40da-41ed-907a-fcf31b8203e5@googlegroups.com>
Hi all,

I have a date1 as date, cHour1 as string,date2 as date, cHour2 as string

I want compare date1+hour1=date2+hour2

any suggestion?

Paulo Oliveira

[toc] | [next] | [standalone]


#5320

FromPilks <richardp@lukhozi.co.za>
Date2013-06-04 07:52 -0700
Message-ID<fedf5aef-171a-4989-bda6-6c7238b5e149@googlegroups.com>
In reply to#5319
Paulo
> I want compare date1+hour1=date2+hour2
> 
Why not:
 dtos(date1)+hour1=dtos(date2)+hour2
?

Richard
> 
> 
> any suggestion?
> 
> 
> 
> Paulo Oliveir

[toc] | [prev] | [next] | [standalone]


#5321

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2013-06-04 17:57 +0200
Message-ID<b16h3kF6ma5U1@mid.individual.net>
In reply to#5319
Hi Paulo,

> I have a date1 as date, cHour1 as string,date2 as date, cHour2 as
> string
> 
> I want compare date1+hour1=date2+hour2

use a numeric value as hours with fractions:

nHours1 := ( Date1 - ConDate( 1900, 1, 1 ) * 24 ) + ( Secs( Hour1 ) /
3600 )

nHours2 := ( Date2 - ConDate( 1900, 1, 1 ) * 24 ) + ( Secs( Hour2 ) /
3600 )

Wolfgang


-- 

[toc] | [prev] | [next] | [standalone]


#5322

From"Arne Ortlinghaus" <Arne.Ortlinghaus@acs.it>
Date2013-06-04 18:05 +0200
Message-ID<kol2vp$ofd$1@dont-email.me>
In reply to#5319
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}

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.clipper.visual-objects


csiph-web