I was playing around with some of the different time formats and noticed that the INTEGER value that results from mathematical operations on two TIME vales will be in either seconds or thousandths of seconds, it will never been in tenths or hundredths, even if the TIME FORMAT is set for tenths or hundredths.  I am running 9.5.2.11008 x64, so I can only speak to that version.  If you run the code below, you will see what I mean.  The only time 60 is displayed is when the TIME FORMAT ends SS.  Whenever the TIME FORMAT command has a subsecond setting (SS.<S or SS or SSS>), 60000 is displayed.
                                        Jason

SET VAR vttstart TIME = NULL
SET VAR vttend TIME = NULL
SET VAR vttdif INTEGER = NULL
SET VAR vttmsg TEXT = NULL

SET VAR vttstart = 10:10:10.123
SET VAR vttend = 10:11:10.123

SET TIME FORMAT HH:MM:SS AP
SET VAR vttmsg = 'TIME FORMAT:' & (CVAL('TIME'))
PAUSE 2 USING .vttmsg CAPTION 'TIME FORMAT' ICON INFO
SET VAR vttdif = .vttend - .vttstart
SET VAR vttmsg = 'SECONDS:' & (CTXT(.vttdif))
PAUSE 2 USING .vttmsg CAPTION 'TIME DIFFERENCE' ICON INFO

SET TIME FORMAT HH:MM:ss.s AP
SET VAR vttmsg = 'TIME FORMAT:' & (CVAL('TIME'))
PAUSE 2 USING .vttmsg CAPTION 'TIME FORMAT' ICON INFO
SET VAR vttdif = .vttend - .vttstart
SET VAR vttmsg = 'TENTHS OF A SECOND:' & (CTXT(.vttdif))
PAUSE 2 USING .vttmsg CAPTION 'TIME DIFFERENCE' ICON INFO

SET TIME FORMAT HH:MM:ss.ss AP
SET VAR vttmsg = 'TIME FORMAT:' & (CVAL('TIME'))
PAUSE 2 USING .vttmsg CAPTION 'TIME FORMAT' ICON INFO
SET VAR vttdif = .vttend - .vttstart
SET VAR vttmsg = 'HUNDREDTHS OF A SECOND:' & (CTXT(.vttdif))
PAUSE 2 USING .vttmsg CAPTION 'TIME DIFFERENCE' ICON INFO

SET TIME FORMAT HH:MM:ss.sss AP
SET VAR vttmsg = 'TIME FORMAT:' & (CVAL('TIME'))
PAUSE 2 USING .vttmsg CAPTION 'TIME FORMAT' ICON INFO
SET VAR vttdif = .vttend - .vttstart
SET VAR vttmsg = 'THOUSANDS OF A SECOND:' & (CTXT(.vttdif))
PAUSE 2 USING .vttmsg CAPTION 'TIME DIFFERENCE' ICON INFO

CLEAR VAR vttstart,vttend,vttdif,vttmsg

RETURN


Jason Kramer
University Archives and Records Management
002 Pearson Hall
(302) 831 - 3127 (voice)
(302) 831 - 6903 (fax)
On 10/17/2012 9:32 AM, Dennis McGrath wrote:

Parhaps one of these days we will see:

 

DTDiff(datetime,datetime) returns a string in the format ‘Days,Hours,Minutes,Seconds’

i.e. DTDiff(‘10/1/2012 12:45:00 PM’,’10/2/2012 3:01:03 AM’)

returns ‘0,2,16,3’  regardless of the time settings.

 

 

Dennis McGrath

Software Developer

QMI Security Solutions

1661 Glenlake Ave

Itasca IL 60143

630-980-8461

[email protected]

From: [email protected] [mailto:[email protected]] On Behalf Of Bill Downall
Sent: Wednesday, October 17, 2012 6:39 AM
To: RBASE-L Mailing List
Subject: [RBASE-L] - Re: Datetime tutorial

 

Yes, it's milliseconds if your time format includes ss.sss, it's centiseconds if time format is ss.ss, deciseconds if time format contains ss.s, and seconds if time format has ss.

 

If you subtract DATES from each other, the integer is always days.

 

You should always check or enforce the appropriate time format before doing subtraction with time or date-time values.  ADDSEC gives the same result no matter what the format, so I would recommend you use that instead of just adding integers to datetime or time, the way we had to in the very old days. 

 

Adding integers to dates should always be a date, integer number of days away, but ADDDAY is clear in its definition, so I would recommend that, too.

 

Bill

On Wed, Oct 17, 2012 at 2:55 AM, Alastair Burr <[email protected]> wrote:

What else can it mean, Bill? Does it return milliseconds if the time format does? Or minutes if the seconds are not included?

I couldn’t find anything in the help files because I could find a subject to look under.

 

Regards,

Alastair.

 

 

 

From: Bill Downall

Sent: Tuesday, October 16, 2012 7:52 PM

Subject: [RBASE-L] - Re: Datetime tutorial

 

Karen,

 

Be careful with the definition of that integer you would get from subtracting one time from another. Sometimes it could mean seconds, but depending on your TIME format, it could mean something else, too.

 

Bill

 

R>set var vthen = .#NOW

R>sho v vthen

10/16/2012  2:49:03 PM

R>set var vlapsed1 = (.#now - .vthen)

R>sho v vlapsed%

Variable             = Value                                   Type

--------------------   ------------------------------          -------

vlapsed1             = 23                                       INTEGER

 

R>sho time

TIME format     HH:MM:SS AP

TIME sequence   HHMMSS

R>set time format 'HH:MM:SS.sss'

R>set var vlapsed2 = (.#now - .vthen)

R>sho v vlapsed%

Variable             = Value                                   Type

--------------------   ------------------------------          -------

vlapsed1             = 23                                       INTEGER

vlapsed2             = 62208                                    INTEGER

 

 

On Tue, Oct 16, 2012 at 2:42 PM, Alastair Burr <[email protected]> wrote:

Karen,

 

You have had some answers about the SETting of the variable but you also sneaked in a comment about subtracting one date/time from another.

 

You’re right, as far as I know, you get an integer which is correct but meaningless <g>.

 

However, you can convert that number into a time using the ADDSEC function:

 

SET VAR vNoNoneSenseTime = (ADDSEC(‘0:00:00’, .vYourResult)

 

As long as it is less that 24 hours you’re fine. If not you have to work out the days first! And, guess what? You can use the ADDDAY function almost the same way!

 

By the way, you can use a negative value for the second component to subtract time or days.

 

I am sure I must have said it here before but these are my most used and most loved R:Base functions. If the time ones would go beyond the 24 hour mark they’d be even better. (We all say things like “give it 48 hours”.)

 

Regards,

Alastair.

 

 

Sent: Tuesday, October 16, 2012 4:08 PM

Subject: [RBASE-L] - Datetime tutorial

 

Here's one for the slow list...  So far in my RBase career, I have
been blessedly spared from doing time arithmetic.  That's about
to change.

Although this client has purchased some version of 9.x, for the
immediate need this will be done in 7.6.

I'm still trying to get an answer on whether I need to track time only,
or whether I will need a DateTime.  I've been playing around with
DateTime and am totally confused.  I've read all the help screens
I could find but mine aren't working that way!

If I do:   SET VAR vDatetime = .#NOW
the datatype is Text and cannot be used for arithmetic

If I do:  SET VAR vDatetime DATETIME = .#NOW
I get an error message about my variable not having the same data type

If I do:  SET VAR vDatetime DATETIME = (DATETIME(.#date, .#time))
then I do get a datetime variable, and it appears I can use these for
arithmetic.  If I subtract 2 datetime variables I get an integer which I
suspect is in seconds, right?  So basically the .#now is not good for calcs?

Now part two.  I set up a temp table with a column with DATETIME
data type, and am incapable of getting a value loaded.  Using my now
valid DateTime variables, I try to do an insert and I get the same error
message above about invalid data types:
       insert into testklt (onedatetime) values .vDateTime

Hard to believe I've gotten away with not a single DateTime in my clients,
isn't it??   Well, now I might need to use it.  
      

Karen

 

 





Reply via email to