Date & Time Calculations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Date and Time Calculation > Time to Value Commands >

Date & Time Calculations

TTV. - Time to Value

Previous Top Next


MiniRobotLanguage (MRL)

 

TTV. Command

Time to Value

 

 

Intention

 

What is the difference between  time and value?

A time is this: "08:37".  A time is also this ""08:37:15", which includes seconds.

While this "08:37:15:2544" is also a valid time, we don't need Milliseconds here because TTV. does only work down to seconds. A value is this: "31006" which is about "07:36".

 

What does TTV. do?

TTV. delivers you the "number of seconds since midnight" for a specified time. It will tell you "How many seconds old your day is.

 

For example, you will get a  "31151" as value for the "07:39:" and

a  "149386" as value for the "02.01.2010", which is one day later.

 

What do i do with these values?

Values that represent a time, are more easy to handle. Store them in files, do calculations with them. A time is just a number with DTV. Of course you can also add or subtract seconds to / from this value.

 

Can i convert that number back to a time?

Yes, finally you can convert that value back to a valid date using VTT. (Value to Time).

 

One thing to know is, that if you specify the term "now" instead of a date, then the current time will be used. The same will happen, if you omit P1 or if you leave P1 empty.

 

Usage is simple:

 

TTV.

STS.DUMP

MBX.!

 

graphic

 

which is actual time (in seconds after midnight)  as a value on TOS.

 

If we provide P1, the variable will be used as Source and Target, if its a variable.

Like this:

 

$$TIM=now

TTV.$$TIM

MBX.$$TIM

 

will deliver this result:below (left picture). If you leave away the first line and just write:

 

TTV.$$TIM

MBX.$$TIM

 

you will get a zero, like in the second picture. Why this?

 

graphic       graphic

 

The reason is, that undefined variables will not be resolved. In that case the script tries to get the "date-value" for $$TIM which is zero, like it is zero for any invalid (non-time) string..

 

' This will work as expected and return the value for "Now"

$$TIM=

TTV.|$$TIM

MBX.$$TIM

 

' This will do just the same (P1 = empty)

TTV.|$$TIM

MBX.$$TIM

 

Now we will get a value for another time. But what if we have times without the seconds?

Let us try:

 

' We specify only the hours

TTV.10|$$TIM

DBV.$$TIM

' Result is 36000

 

' We specify Hours and Minutes

TTV.10:00|$$TIM

DBV.$$TIM

' Result is 36000

 

' We specify the complete time

TTV.10:00:00|$$TIM

DBV.$$TIM

' Result is 36000

 

' We specify even Milliseconds

TTV.10:00:00:0000|$$TIM

DBV.$$TIM

 

As you can see in this example, the result is always the same. Missing time-informations are being treated as zero. If you omit minutes or seconds, they are zero'ed.

The Milliseconds do not play a role here and are simply ignored.

 

Of course we can use variables. Here is an example:

 

$$TIA=10

TTV.$$TIA|$$TIM

DBV.$$TIM

 

It works. The result is 36000 as expected.

 

 

' Get the time-value into variable $$TIA

$$TIA=10:00:30

TTV.$$TIA|$$TIM

 

' Subtract 156 Seconds

CAL.$$TIM=$$TIM-156

VTT.$$TIM|$$TIA

 

' Print it in the editor

DBV.$$TIA

ENR.

 

Important:

You do need to specify the time in the format "hh:mm:ss", but you can leave parts away from the right side. You can not leave away the hh-part.

 

 

 

Syntax

 

TTV.[P1][|P2]

 

 

Parameter Explanation

 

 

P1 - (can be omitted or empty) If omitted or empty, the

    actual time (Now) is used. The result will be placed on

    the TOS. The same will happen, if the term now is given,

    no matter if in an variable or direct. If you specify

    an variable in P1, and P2 is omitted, then the result will

    be placed in that variable.

 

P2 -  (optional) If specified, this variable will be used for the

     resulting value.

 

 

 

Example

 

'**********************************************

' TTV. - Sample

'**********************************************

'

TTV.

DBV.$$000

PAU.1

TTV.

VTT.$$000

DBV.$$000

ENR.

 

 

'**********************************************

' TTV. - Sample

'**********************************************

'

TTV.now|$$TIM

DBV.$$TIM

VTT.$$TIM

DBV.$$TIM

ENR.

 

 

'**********************************************

' TTV. - Sample

'**********************************************

'

TTV.now

VTT.$$000

DBV.$$000

ENR.

 

'**********************************************

' TTV. - Sample

'**********************************************

'

TTV.10:00:00|$$TIM

DBV.$$TIM

' Result is 36000

 

 

 

 

Remarks

 

-

 

 

 

Limitations:

 

These time-calculations depend on th current system time. If your system time is wrongly set, the command may also deliver the wrong time.

 

 

 

See also:

 

    1.5.1.3. Using Variables

    DAT. - Date and Time Information (System independent)

    TTV. - Time to Value

    DTV. - Date to Value

    VTD. - Value to Date

    DTC. - Date and Time Calculation

    VTF. - Verify Time Format

    VDF. - Verify Date Format

    IDC. / NDC. - If Date Command

    CAL. - mathematical CALculation

    CAX. - Calculate Extended