Dates

The date formatting feature uses the go date formatting, as such the same format layouts are expected. Check https://gosamples.dev/date-time-format-cheatsheet/ for information on how the form the formats. Default format 2006-01-02T15:04:05Z07:00. Some dt prefixed functions returns timeObject, which is golang struct. This struct may be used while calling multiple functions in a pipe, check examples for how-to-use tips. All timeObject related functions description could be found on the official golang documentation portal. Check all functions that starts from func (t Time).

Almost every account have default time related configurations, like timezone and formats. Timezone may not exist for accounts that shares many timezones (e.g. most of the USA accounts), in this case timezone should be configured by account owners.

Available variables:

{{ $timeZone := .Data.ErplyApi.ConfigurationList.timezone }} <!-- Europe/Tallinn -->
{{ $dateFormat := .Data.ErplyApi.ConfigurationList.go_date_format }} <!-- 02.01.2006 -->
{{ $monthDayFormat := .Data.ErplyApi.ConfigurationList.go_month_day_format }} <!-- 02.01 -->
{{ $timeFormat := .Data.ErplyApi.ConfigurationList.go_time_format }} <!-- 15:04:05 -->
{{ $hourMinuteFormat := .Data.ErplyApi.ConfigurationList.go_hour_minute_format }} <!-- 15:04 -->
{{ $dateTimeFormat := .Data.ErplyApi.ConfigurationList.go_date_time_format }} <!-- 02.01.2006 15:04:05 -->

Duration formatting syntax

The duration formatting feature partially inherits the go time formatting, so those are placeholders:

  • 00 - years
  • 01 - months
  • 02 - days
  • 03 - hours
  • 04 - minutes
  • 05 - seconds

Sample usage:

{{ formatDuration "2450000m35s" "00 year(s) 01 month(s) 02 day(s) 03 hour(s) 04 minute(s) and 05 second(s)" }}
<!-- Result: 4 year(s) 8 month(s) 1 day(s) 9 hour(s) 20 minute(s) and 35 second(s) -->
Name Description Function arguments Usage
unixToDate Convert a unix value to the requested date format in the selected timezone unixToDate(unix, timeZone, format) string {{ unixToDate 150000 “UTC” “2006-01-02” }}
formatDate Convert one specific date format to another formatDate(dateValue, fromFormat, toFormat, timeZone) string {{ formatDate “2022-11-11” “2006-01-02” “2006/02/01” “GMT” }}
serverTime Returns unix time in seconds serverTime() int64 {{ serverTime }}
serverTimeIn Returns current datetime in provided timezone and format serverTimeIn(timeZone, format) string {{ serverTimeIn “GMT” “2006-01-02” }}
addDate Adds amount of unitOfTime to the datetime and returns datetime in default format addDate(datetime, unitOfTime, amount) string {{ addDate “2023-01-02” “month” -6 }}
addDate same as previous, but with optional format parameter addDate(datetime, unitOfTime, amount, format) string {{ addDate “2023-01-02” “month” 6 “2006/02/01” }}
dtFromDateTime To get timeObject from the datetime dtFromDateTime(datetime, format, timezone) timeObject {{ dtFromDateTime “2023-01-02” “2006-01-02” “GMT” }}
dtCurrent Current time (returns default format) dtCurrent() timeObject {{ dtCurrent }}
dtCurrentIn Current time in TZ (returns default format) dtCurrentIn(timezone) timeObject {{ dtCurrentIn “GMT” }}
dtAdjustDate add or subtract unit of time to/from datetime dtAdjustDate(timeObject, unitOfTime, amount) timeObject {{ dtAdjustDate timeObject “month” 6}}
dtFirstDayOfWeek First day of week, if isSunday true then week starts from Sunday dtFirstDayOfWeek(timeObject, isSunday) timeObject {{ dtFirstDayOfWeek timeObject false }}
dtLastDayOfWeek Last day of week, if isSunday true then week starts from Sunday dtLastDayOfWeek(timeObject, isSunday) timeObject {{ dtLastDayOfWeek timeObject false }}
dtFirstDayOfMonth First day of month dtFirstDayOfMonth(timeObject) timeObject {{ dtFirstDayOfMonth timeObject }}
dtLastDayOfMonth Last day of month dtLastDayOfMonth(timeObject) timeObject {{ dtLastDayOfMonth timeObject }}
dtFirstDayOfYear First day of the year dtFirstDayOfYear(timeObject) timeObject {{ dtFirstDayOfYear timeObject }}
dtLastDayOfYear Last day of the year dtLastDayOfYear(timeObject) timeObject {{ dtLastDayOfYear timeObject }}
dtToFormat Convert timeObject to string using format dtToFormat(timeObject, format) string {{ dtToFormat timeObject “2006/02/01” }}
dtToTimezone Set timeObject into a different timezone dtToTimezone(timeObject, timezone) timeObject {{ dtToTimezone timeObject “UTC” }}
dtToFormatIn Set timezone and format at the same time dtToFormatIn(timeObject, format, timezone) string {{ dtToFormatIn timeObject “2006/02/01” “UTC” }
dtFirstDayOfPreviousMonthInFormat Datetime manipulation in format, returns string dtFirstDayOfPreviousMonthInFormat(timeObject, format) string {{ dtFirstDayOfPreviousMonthInFormat timeObject “2006/02/01” }}
dtFirstDayOfCurrentMonthInFormat Datetime manipulation in format, returns string dtFirstDayOfCurrentMonthInFormat(timeObject, format) string {{ dtFirstDayOfCurrentMonthInFormat timeObject “2006/02/01” }}
dtFirstDayOfNextMonthInFormat Datetime manipulation in format, returns string dtFirstDayOfNextMonthInFormat(timeObject, format) string {{ dtFirstDayOfNextMonthInFormat timeObject “2006/02/01” }}
dtLastDayOfPreviousMonthInFormat Datetime manipulation in format, returns string dtLastDayOfPreviousMonthInFormat(timeObject, format) string {{ dtLastDayOfPreviousMonthInFormat timeObject “2006/02/01” }}
dtLastDayOfCurrentMonthInFormat Datetime manipulation in format, returns string dtLastDayOfCurrentMonthInFormat(timeObject, format) string {{ dtLastDayOfCurrentMonthInFormat timeObject “2006/02/01” }}
dtLastDayOfNextMonthInFormat Datetime manipulation in format, returns string dtLastDayOfNextMonthInFormat(timeObject, format) string {{ dtLastDayOfNextMonthInFormat timeObject “2006/02/01” }}
dtFirstDayOfPreviousYearInFormat Datetime manipulation in format, returns string dtFirstDayOfPreviousYearInFormat(timeObject, format) string {{ dtFirstDayOfPreviousYearInFormat timeObject “2006/02/01” }}
dtFirstDayOfCurrentYearInFormat Datetime manipulation in format, returns string dtFirstDayOfCurrentYearInFormat(timeObject, format) string {{ dtFirstDayOfCurrentYearInFormat timeObject “2006/02/01” }}
dtFirstDayOfNextYearInFormat Datetime manipulation in format, returns string dtFirstDayOfNextYearInFormat(timeObject, format) string {{ dtFirstDayOfNextYearInFormat timeObject “2006/02/01” }}
dtLastDayOfPreviousYearInFormat Datetime manipulation in format, returns string dtLastDayOfPreviousYearInFormat(timeObject, format) string {{ dtLastDayOfPreviousYearInFormat timeObject “2006/02/01” }}
dtLastDayOfCurrentYearInFormat Datetime manipulation in format, returns string dtLastDayOfCurrentYearInFormat(timeObject, format) string {{ dtLastDayOfCurrentYearInFormat timeObject “2006/02/01” }}
dtLastDayOfNextYearInFormat Datetime manipulation in format, returns string dtLastDayOfNextYearInFormat(timeObject, format) string {{ dtLastDayOfNextYearInFormat timeObject “2006/02/01” }}
dtFuture Datetime manipulation to get the nearest future quarter, half or full hour dtFuture(timeObject, type) timeObject {{ dtFuture timeObject “quarter” }}
dtStartOfDay Datetime manipulation to get the start of the day time object dtStartOfDay(timeObject) timeObject {{ dtStartOfDay timeObject }}
dtEndOfDay Datetime manipulation to get the end of the day time object dtEndOfDay(timeObject) timeObject {{ dtEndOfDay timeObject }}
dtNearestWeekday returns nearest weekday of the timeObject. true - calculates in feature, otherwise in past dtNearestWeekday(timeObject, weekday, false?) timeObject {{ dtNearestWeekday timeObject, “Monday” }}
convertTimeUnits Converts one time unit to another. Possible units: s, m, h. convertTimeUnits(amount, from, to) float64 {{ convertTimeUnits 5 “h” “s” }}
parseDuration Parses text formated duration to the time.Duration. Accepts value in format 2h45m35.5s parseDuration(dur) time.Duration {{ parseDuration “245m” }}
parseDuration (roundTo) parseDuration could also receive optional roundTo setting, which is one of s, m and h parseDuration(dur, roundTo) time.Duration {{ parseDuration “245m35s” “m” }}
formatDuration Formats passed duration to the specified format. Receives time.Duration or string types (check syntax) formatDuration(dur, format) string {{ formatDuration “245m” “05 sec” }}
formatDuration (roundTo) formatDuration with optional roundTo param, which is one of s, m and h formatDuration(dur, format, roundTo) string {{ formatDuration “245m22.6s” “05 sec” “s” }}
Unix Its possible to get the unix value on any timeObject timeObject.Unix {{ $timeObject.Unix }}

Example when using current accounts time zone.

{{ $timeZone :=.Data.ErplyApi.ConfigurationList.timezone | toString }}
{{ unixToDate 1683201802 $timeZone "2006-02-01" }}
{{ formatDate "2022-11-11" "2006-01-02" "2006/02/01" $timeZone }}

Examples using dt functions:

<!-- DT date manipulations -->

<p>
  <!-- Get a usable date object -->
  <!-- Basic current server time (UTC) -->
  Server current time: {{ dtCurrent }}
</p>
<p>
  <!-- Get current time in a specific timezone / location -->
  <!-- #1 parameter here is the tz timezone identifier value
  get a reference for the available values in https://en.wikipedia.org/wiki/List_of_tz_database_time_zones -->
  Current time in TZ: {{ dtCurrentIn "America/New_York" }}
</p>
<p>
  <!-- Use an input in any possible format from another source -->
  <!-- #1 parameter is the input date value -->
  <!-- #2 parameter is the input date format, use the https://gosamples.dev/date-time-format-cheatsheet/ to read on how the format works  -->
  <!-- #3 is the timezone tz identifier value of the output time -->
  Time conversion from another format: {{ dtFromDateTime "2023-06-06T15:12:12Z07:00"
  "2006-01-02T15:04:05Z07:00" "America/New_York" }}
</p>

<!-- Manipulate the value of the date-->

<!-- Reduce by 1 year -->
<p>Current time reduced by 1 year: {{ dtAdjustDate dtCurrent "year" -1 }}</p>
<!-- Add 1 year -->
<p>Current time plus 1 year: {{ dtAdjustDate dtCurrent "year" 1 }}</p>
<!-- Reduce by 1 month -->
<p>Current time reduced by 1 month: {{ dtAdjustDate dtCurrent "month" -1 }}</p>
<!-- Add 1 month -->
<p>Current time plus 1 month: {{ dtAdjustDate dtCurrent "month" 1 }}</p>
<!-- Reduce by 1 day -->
<p>Current time reduced by 1 day: {{ dtAdjustDate dtCurrent "day" -1 }}</p>
<!-- Add 1 day -->
<p>Current time plus 1 day: {{ dtAdjustDate dtCurrent "day" 1 }}</p>

<!-- Get specific values -->
<!-- First and last day of week -->
<!-- #1 value of one of the provided functions: dtCurrent, dtCurrentIn or dtFromDateTime -->
<!-- #2 boolean value - true if week start day is Sunday and false for Monday -->
<p>First day of week(monday): {{ dtFirstDayOfWeek dtCurrent false }}</p>
<p>First day of week(sunday): {{ dtFirstDayOfWeek dtCurrent true }}</p>
<p>Last day of week(monday): {{ dtLastDayOfWeek dtCurrent false }}</p>
<p>Last day of week(sunday): {{ dtLastDayOfWeek dtCurrent true }}</p>

<!-- First and last day of the month -->
<!-- #1 value of one of the provided functions: dtCurrent, dtCurrentIn or dtFromDateTime -->
<p>First day of month: {{ dtFirstDayOfMonth dtCurrent }}</p>
<p>Last day of month: {{ dtLastDayOfMonth dtCurrent }}</p>

<p>First day of next month: {{ dtAdjustDate dtCurrent "month" 1 | dtFirstDayOfMonth }}</p>
<p>First day of previous month: {{ dtAdjustDate dtCurrent "month" -1 | dtFirstDayOfMonth }}</p>

<!-- First and last day of the year -->
<!-- #1 value of one of the provided functions: dtCurrent, dtCurrentIn or dtFromDateTime -->
<p>First day of the year: {{ dtFirstDayOfYear dtCurrent }}</p>
<p>Last day of the year: {{ dtLastDayOfYear dtCurrent }}</p>

<p>First day of next year: {{ dtAdjustDate dtCurrent "year" 1 | dtFirstDayOfYear }}</p>
<p>Last day of previous year: {{ dtAdjustDate dtCurrent "year" -1 | dtLastDayOfYear }}</p>

<!-- Format the date to anything thats needed -->
<!-- #1 dt time object from any of the previous functions -->
<!-- #2 in what format you need to get the date time format, use https://gosamples.dev/date-time-format-cheatsheet/ as date format reference -->
<p>Date to UnixDate: {{ dtToFormat dtCurrent "Mon Jan _2 15:04:05 MST 2006" }}</p>
<p>Date to RFC822: {{ dtToFormat dtCurrent "02 Jan 06 15:04 MST" }}</p>
<p>Date to RFC1123: {{ dtToFormat dtCurrent "Mon, 02 Jan 2006 15:04:05 MST" }}</p>
<p>Date to RFC3339Nano: {{ dtToFormat dtCurrent "2006-01-02T15:04:05.999999999Z07:00" }}</p>
<p>Date only: {{ dtToFormat dtCurrent "2006-01-02" }}</p>
<p>Time only: {{ dtToFormat dtCurrent "15:04:05" }}</p>
<p>Custom: {{ dtToFormat dtCurrent "15:04:05 2006/01/02" }}</p>

<!-- Chain current time -> add 1 year -> first day of the year -> to my format -->
<!-- With a set variable -->
<p>
  {{ $firstDayOfNextYear := dtAdjustDate dtCurrent "year" 1 | dtFirstDayOfYear }}
  First day of next year in RFC822: {{ dtToFormat $firstDayOfNextYear "02 Jan 06 15:04 MST" }}
</p>

<!-- Use helper functions -->
<!-- #1 date data from the previous functions -->
<!-- #2 what format to concert to -->
<!-- Note that these functions alter the date by 1 depending if its first or last, so further adjustments to the input date here is not needed -->
<p>First day of pervious month: {{ dtFirstDayOfPreviousMonthInFormat dtCurrent "02 Jan 06 15:04 MST"
  }}</p>
<p>First day of current month:{{ dtFirstDayOfCurrentMonthInFormat dtCurrent "02 Jan 06 15:04 MST"
  }}</p>
<p>First day of next month:{{ dtFirstDayOfNextMonthInFormat dtCurrent "02 Jan 06 15:04 MST" }}</p>
<p>First day of pervious year:{{ dtFirstDayOfPreviousYearInFormat dtCurrent "02 Jan 06 15:04 MST"
  }}</p>
<p>First day of current year:{{ dtFirstDayOfCurrentYearInFormat dtCurrent "02 Jan 06 15:04 MST"
  }}</p>
<p>First day of next year:{{ dtFirstDayOfNextYearInFormat dtCurrent "02 Jan 06 15:04 MST" }}</p>

<p>Last day of pervious month: {{ dtLastDayOfPreviousMonthInFormat dtCurrent "02 Jan 06 15:04 MST"
  }}</p>
<p>Last day of current month:{{ dtLastDayOfCurrentMonthInFormat dtCurrent "02 Jan 06 15:04 MST"
  }}</p>
<p>Last day of next month:{{ dtLastDayOfNextMonthInFormat dtCurrent "02 Jan 06 15:04 MST" }}</p>
<p>Last day of pervious year:{{ dtLastDayOfPreviousYearInFormat dtCurrent "02 Jan 06 15:04 MST"
  }}</p>
<p>Last day of current year:{{ dtLastDayOfCurrentYearInFormat dtCurrent "02 Jan 06 15:04 MST" }}</p>
<p>Last day of next year:{{ dtLastDayOfNextYearInFormat dtCurrent "02 Jan 06 15:04 MST" }}</p>

<!-- DT future -->
<h2>Get nearest future quarter, half or full hour for a datetime</h2>

{{ $sample := dtFromDateTime "12:14" "03:04" "GMT" }}

<p>{{ dtToFormat (dtFuture $sample "quarter") "03:04" }}</p>
<p>{{ dtToFormat (dtFuture $sample "half") "03:04" }}</p>
<p>{{ dtToFormat (dtFuture $sample "full") "03:04" }}</p>

<!-- Start and end of the day -->
<p>{{ $timeZone := toString .Data.ErplyApi.ConfigurationList.timezone }}</p>
<p>{{ $today := dtCurrentIn $timeZone }}</p>

{{ $start := dtStartOfDay $today }}
{{ $end := dtEndOfDay $today }}

<!-- Get Unix on any timeObject (from any of the helpers that return that type) value -->
<p>{{ $start.Unix }}</p>
<p>{{ $end.Unix }}</p>