<< Click to Display Table of Contents >> Navigation: 3. Script Language > Date and Time Calculation > Time to Value Commands > Date & Time Calculations |
MiniRobotLanguage (MRL)
DTV. Command
Date to Value
Intention
Using DTV. you can convert a date to the equivalent number of days since January 1601.
Now you can do any sort of math using this number. When you're done, just use VTD. to convert the result back into a valid date! This way calculations with days get very easy.
Example:
VTD.1|$$RES
MBX.$$RES
' Will return "01-91-1601"
DTV.01.01.1601|$$RES
MBX.$$RES
' Will return "1"
' Using "Now" the current Date is used.
DTV.now|$$RES
VTD.$$RES|$$RES
MBX.$$RES
What is the difference between date and value?
A date is this: "01.01.2010".
A value is this: "149386". This the number of days that have passed, since January 1601.
What does DTV. do?
DTV. delivers you the value for a date. That is the number of the given day,
counted from January 1601, one for each day.
For example, you will get a "149385" as value for the "01.01.2010" 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 date, are more easy to handle. Store them in files, do calculations with them. A date is just a number with DTV. Of course you can also add or subtract days from this value.
Can i convert that number back to a date?
Yes, finally you can convert that value back to a valid date using VTD. (Value to Date).
One thing to know is, that if you specify the term "now" instead of a date, then the current date will be used. The same will happen, if you omit P1 or if you leave P1 empty.
Usage is simple:
DTV.
STS.DUMP
MBX.!
which is today's value on TOS.
If we provide P1, the variable will be used as Source and Target, if its a variable.
Like this:
$$TIM=now
DTV.$$TIM
MBX.$$TIM
will deliver this result:below (left picture). If you leave away the first line and just write:
DTV.$$TIM
MBX.$$TIM
you will get a zero, like in the second picture. Why this?
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-date) string..
' This will work as expected and return the value for "Now"
$$TIM=
DTV.|$$TIM
MBX.$$TIM
' This will do just the same (P1 = empty)
DTV.|$$TIM
MBX.$$TIM
Now we will get a value for another date, let us take the 12.12.2012.
Like this:
DTV.12.12.2012|$$TIM
MBX.$$TIM
Of course we can use variables. Here is an example:
$$DAT=12.12.2012
DTV.$$DAT|$$TIM
MBX.$$TIM
It works. The result is in the second variable $$TIM.
Important:
You need to specify the date in the format "dd.mm.yyyy". Giving a useless input you will get:
a) If there are no numbers contained, Result is "0"
b)If there are numbers contained, you will get a date based on the 01.01.2001 as result. For example:
$$DAT=Anton
DTV.$$DAT|$$TIM
MBX.$$TIM
'Result is "0"
$$DAT=Anton6
DTV.$$DAT|$$TIM
MBX.$$TIM
'Result is "06.01.2001"
Syntax
DTV.[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
'**********************************************
' DTV. - Sample
'**********************************************
'
$$TIA=01.01.2010
$$TIB=02.01.2010
DTV.$$TIA
DTV.$$TIB
CAL.$$RES=($$TIB-$$TIA)
DBP.$$RES, $$TIB,$$TIA
ENR.
'**********************************************
' DTV. - Sample
'**********************************************
'
$$DAT=12.12.2012
DTV.$$DAT|$$TIM
MBX.$$TIM
'**********************************************
' DTV. - Sample
' Convert Date to Number, Add 1 day and convert
' Number back to Date
'**********************************************
'
$$DAT=12.12.2012
DTV.$$DAT|$$TIM
VIC.$$TIM
VTD.$$TIM
MBX.$$TIM
' Result is 13.12.2012
ENR.
Remarks
-
Limitations:
All Date-calculations should be accurate up to a Millisecond at least back until 1601.
You can not specify Dates before the 01-01-1601. Doing so will always return "0".
See also:
• DAT. - Date and Time Information (System independent)
• DTC. - Date and Time Calculation
• IDC. / NDC. - If Date Command
• CAL. - mathematical CALculation