Date & Time Calculations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Date and Time Calculation > DTO. - Date Time Operations >

Date & Time Calculations

DTO.AddSeconds - Add Seconds to a Time

Previous Top Next


MiniRobotLanguage (MRL)

 

DTO.AddSeconds Command

Add or Subtract Seconds from a Time String

 

Intention

 

The DTO.AddSeconds command allows you to add a specific number of seconds to a given time string. It intelligently handles overflows, so if you add enough seconds to pass the 60-second mark, it correctly increments the minutes and hours.

 

You can also use this command to subtract seconds by providing a negative value. The time will wrap around midnight (00:00:00) if necessary.

 

Syntax

 

DTO.AddSeconds|time|seconds|[format]|[$$RES]

 

Parameter Explanation

 

time - The base time string to which seconds will be added.

 

seconds - The number of seconds to add. Use a negative integer to subtract seconds.

 

format - (Optional) The format of the input and output time string (e.g., "HH:MM:SS"). Defaults to "HH:MM:SS" if omitted.

 

$$RES - (Optional) Variable to store the resulting time string.

 

Example

 

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

' DTO.AddSeconds - Sample

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

'

' --- Sample 1: Simple addition ---

$$TIM = "10:15:30"

DTO.AddSeconds|$$TIM|20||$$RES

MBX.New Time: $$RES ' Result: 10:15:50

'

' --- Sample 2: Addition with minute overflow ---

$$TIM = "10:59:50"

DTO.AddSeconds|$$TIM|20||$$RES

MBX.New Time (Overflow): $$RES ' Result: 11:00:10

'

' --- Sample 3: Subtraction (negative seconds) ---

$$TIM = "00:00:05"

DTO.AddSeconds|$$TIM|-10||$$RES

MBX.New Time (Wrapped): $$RES ' Result: 23:59:55

ENR.

 

Remarks

 

The command handles time wrap-around at midnight (24:00:00 or 00:00:00) automatically. If you add enough seconds to go past 23:59:59, the time starts over from 00:00:00.

 

Limitations:

 

This command operates on the time component only. It does not track days if the addition causes the time to roll over midnight.

 

See also:

 

    DTO. - Date Time Operations

    DTO.Add Minutes

    DTO.Add Hours

    DTO.Time Diff

    DTO.Get Current Time

    DTC. - Date and Time Calculation