Date & Time Calculations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Date and Time Calculation >

Date & Time Calculations

DTC. - Date and Time Calculations

Previous Top Next


MiniRobotLanguage (MRL)

 

DTC. Command

Date- and Time Calculations

 

 

Intention

 

What is the difference between  date and time?

A date is this: "23.05.2014".

A time is this: "15:12:45".

 

What does DTC. do?

    delivers you Date in any format you want.

    delivers you Time in any format you want.

    allows you to add or

    to subtract from date or time

 

DTC. can give you the current date, or current time.

It can also reformat the current date or time for you into any format you want.

 

It can do any date-/time calculation for you. And also mix date and time calculations.

For example:

 

    What do i get, if i add 5000 seconds and 403 days to the 12.12.2013, 9:12:53 ?

    What date was 12316 seconds before the 01.01.2014?

    What time will be in 5 hours and 15 Minutes from now?

 

These are just examples, to show the flexibility of DTC. Any of these and many more questions can quickly be solved using DTC.

 

In short: Its a complete all-in-one solution for date/time calculations and re-formatting of the result into the format that you like.

When you need to deal with dates or with time, this is the command that may help you.

 

And after all, we have tried hard to make all this as easy as possible, for you.

 

Generally the DTC. command has two modes of operation:

    formatting date and/or time (2 Parameters)

    formatting and calculation (3 Parameters)

 

To give you a quick overview, look at the general use of the 2 or 3 parameters:

 

P1 - is the variable for the source date and it will also receive the result after all

P2 - is the mask for the format of the result

P3 - is the parameter for adding and subtracting to the date/time

 

Note that there are exceptions from this general rules, see the details below in the section "Parameter".

 

Let us first start with an simple example. We have given the term "now" in P1, this shows that we want to get the current date/time. Then this script:

 

DTC.now|yyyy-mm-dd

STS.DUMP

 

Will put the date, formatted like we want it, on the TOS,

The TOS is used, if we do not specify a variable in P1.

 

 

graphic

 

Next, let us use a variable for P1, then we will get the return value in that variable.

Anyway we want to use the term "now" also, to get the actual date.

 

: $$TIM=now

DTC.$$TIM|dd

MBX.$$TIM

 

In the same way you can get any date or time component into the variable.

What date is in 90 days from today?

 

: $$TIM=now

DTC.$$TIM|dd|AD:90

MBX.$$TIM

 

Next lets take a look at time calculations. We can get the actual time in the same way:

 

: $$TIM=now

DTC.$$TIM|hh:nn

MBX.$$TIM

 

And of course we can add and subtract from that also.

What time was 29000 seconds before now?

 

: $$TIM=now

DTC.$$TIM|hh:nn|SS:29000

MBX.$$TIM

 

Sure, this was on another day, lets see which day. We will just need to tweak the format-parameter a bit. Like this:

 

: $$TIM=now

DTC.$$TIM|dd/mm - hh:nn|SS:29000

MBX.$$TIM

 

 

graphic

 

 

 

 

 

 

Syntax

 

DTC.P1|P2[|P3]...[|PX]

 

 

Parameter Explanation

 

 

P1 - (can be empty) Variable with base-time and or base-date,

   or can contain the "now", or can be empty.

   If the term "now" is specified, or P1 evaluates to empty,

    current date and time is taken as base-time for further

    formatting and calculations.

    If variable is given in P1, the result is placed in

    the variable else the result is placed on TOS.

 

P2 -  Output-Mask. Mask that contains the letters below. These will

     be replaced with the values of the date/time-result. You can

     specify the following letters in the output-mask:

 

   y - Year

   m - Month

   d - Day

   h - Hours

   n - Minutes

   s - Seconds

   t - Milliseconds

 

Example: the mask "dd-mm" will be replaced with "12-03" if the date was the 12.03.XXXX. Time works in the same way. You can specify a mask that contains time and date:

 

DTC.now|yyyy-mm-dd,hh:nn

 

If you specify less characters then the original value needs, for example: "yy" instead of "yyyy", then you will get the numbers from the right side, in this case "15", if the result year is 2015.

A mask of "mm-yy" could be for example "03-15" in the march 2015.

 

P3 -  (optional) - Add / Subtract Parameter. If you want to add or subtract time to/from the base-time, then you can do that using P3. Here you specify the amount of time that should be added or subtracted. Generally all Options are made of two uppercase letters. The first letter specifies what to do:

 

A - Add something to the base-time/date

S - Subtract something from the base-time/date

N - Set the value of the base-time/date to this number before

   addition/subtraction.

 

The second letter specifies the time/date parameter that is going to be changed. The used letters are the same like in the list above: Y- Year, until ... T - Milliseconds.

 

You can use any combination of the following options:

 

NY:(number) ' Set Years

AY:(number) ' Add Years

SY:(number) ' Subtract Years

 

NM:(number) ' Set Month

AM:(number) ' Add Month

SM:(number) ' Subtract Month

 

ND:(number) ' Set days

AD:(number) ' Add days

SD:(number) ' Subtract days

 

NH:(number) ' Set hours

AH:(number) ' Add hours

SH:(number) ' Subtract hours

 

NN:(number) ' Set Minutes

AN:(number) ' Add Minutes

SN:(number) ' Subtract Minutes

 

NS:(number) ' Set Seconds

AS:(number) ' Add Seconds

SS:(number) ' Subtract Seconds

 

NT:(number) ' Set Milliseconds

AT:(number) ' Add Milliseconds

ST:(number) ' Subtract Milliseconds

 

For example, your base-time is the 01.01.2010 and you add 1222 Minutes (thats 20 hrs.) and 5 days, you will write:

 

: $$TIM=01.01.2010

' Additions and Subtractions get separated by a comma

DTC.$$TIM|dd-mm-yy|AN:1222,AD:5

MBX.$$TIM

 

 

graphic

 

 

All parameters that are not specified, are replaced with current time! In this case, the base-time is the current time when the script runs. To be more exact we would therefore need to also specify a base-time:

 

: $$TIM=01.01.2010,01:00

DTC.$$TIM|dd-mm-yy|AN:1222,AD:5

MBX.$$TIM

 

and the result will be:

 

graphic

 

You can specify as many Additions and subtractions as you want. Separate them with a comma.

 

 

 

Example

 

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

' DTC. - Sample

' Add 1222 Minutes and 5 Days

' to the time in $$TIM

'

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

: $$TIM=01.01.2010,01:00

DTC.$$TIM|dd-mm-yy|AN:1222,AD:5

MBX.$$TIM

ENR.

 

 

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

' DTC. - Sample

' What date was 149385 days earlier?

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

: $$TIM=now

DTC.$$TIM|dd-mm-yyyy|SD:149385

MBX.$$TIM

 

 

 

Remarks

 

-

 

 

 

Limitations:

 

All Date-calculations should be accurate up to a Millisecond at least back until 1601.

 

 

 

See also:

 

    1.5.1.3. Using Variables

    DAT. - Date and Time Information (System independent)

    VTF. - Verify Time Format

    VDF. - Verify Date Format

    VTT. - Value to Time

    TTV. - Time to Value

    DTV. - Date to Value

    VTD. - Value to Date

    DTC. - Date and Time Calculation

    IDC. / NDC. - If Date Command

    CAL. - mathematical CALculation

    CAX. - Calculate Extended