All templates
Date & TimeBeginner
Convert Datetime to Text
Robomotion•Updated 6 months ago

Overview
Converts a datetime value into a formatted text string using the Robomotion DateTime package. Demonstrates standard and custom output layouts for logging, filenames, and reports.
Convert Datetime to Text
Handling datetime data can be challenging, as numerous formats have been adopted across the globe. Robomotion enables the conversion of datetime variables to predefined and custom formats so that flows can handle data independently of the originating region.
What Convert Datetime to Text can do
- Get now (
Robomotion.DateTime.Now,optLayout: RFC3339,optTimezoneOffset: Local) →msg.current_date_time. - Short date (
Robomotion.DateTime.Format, custom out layout1/2/2006) →msg.formatted_date_time; Function buildsmsg.dialog_text = "Current date in 'short date' text format:\n" + msg.formatted_date_time, thenCore.Dialog.MessageBoxtitledResult(info). - Short time (custom out layout
3:04 PM) → dialogCurrent time in 'short time' text format:\n.... - Long date (custom out layout
January 02, 2006) → dialogCurrent date in 'MMMM dd, yyyy' text format:\n.... - Today sentence (custom out layout
Today is 02th day of January of Year 2006) → dialog showingmsg.formatted_date_timedirectly. - 12-hour time (custom out layout
03:04:05 PM) → dialogCurrent time in 'hh:mm:ss tt' text format:\n.... - Time sentence (custom out layout
It is currently 03 hours 04 minutes and 05 seconds.) → dialog showingmsg.formatted_date_timedirectly. - Full datetime (custom out layout
Monday, 02 January, 2006 | 03:04:05 PM) → dialogToday's date and time is ..., thenCore.Flow.Stop.
Behind the scenes
msg.current_date_timeis captured once at the top as RFC3339; every subsequentRobomotion.DateTime.Formatstep reads the same value and only changesoptCustomOutLayout.Robomotion.DateTime.Formatuses Go-style reference-time layouts —1/2/2006,3:04 PM,January 02, 2006, etc. — where the specific reference numbers (year2006, month01, day02, hour15/03, minute04, second05) mark which field goes where. Literal words likeToday isorof Yearpass through verbatim.msg.formatted_date_timeis reused across every format step, so each dialog always reflects the most recent conversion.