...
1# Date Functions
2
3## now
4
5The current date/time. Use this in conjunction with other date functions.
6
7## ago
8
9The `ago` function returns duration from time.Now in seconds resolution.
10
11```
12ago .CreatedAt"
13```
14
15returns in `time.Duration` String() format
16
17```
182h34m7s
19```
20
21## date
22
23The `date` function formats a date.
24
25Format the date to YEAR-MONTH-DAY:
26
27```
28now | date "2006-01-02"
29```
30
31Date formatting in Go is a [little bit different](https://pauladamsmith.com/blog/2011/05/go_time.html).
32
33In short, take this as the base date:
34
35```
36Mon Jan 2 15:04:05 MST 2006
37```
38
39Write it in the format you want. Above, `2006-01-02` is the same date, but
40in the format we want.
41
42## dateInZone
43
44Same as `date`, but with a timezone.
45
46```
47dateInZone "2006-01-02" (now) "UTC"
48```
49
50## duration
51
52Formats a given amount of seconds as a `time.Duration`.
53
54This returns 1m35s
55
56```
57duration "95"
58```
59
60## durationRound
61
62Rounds a given duration to the most significant unit. Strings and `time.Duration`
63gets parsed as a duration, while a `time.Time` is calculated as the duration since.
64
65This return 2h
66
67```
68durationRound "2h10m5s"
69```
70
71This returns 3mo
72
73```
74durationRound "2400h10m5s"
75```
76
77## unixEpoch
78
79Returns the seconds since the unix epoch for a `time.Time`.
80
81```
82now | unixEpoch
83```
84
85## dateModify, mustDateModify
86
87The `dateModify` takes a modification and a date and returns the timestamp.
88
89Subtract an hour and thirty minutes from the current time:
90
91```
92now | date_modify "-1.5h"
93```
94
95If the modification format is wrong `dateModify` will return the date unmodified. `mustDateModify` will return an error otherwise.
96
97## htmlDate
98
99The `htmlDate` function formats a date for inserting into an HTML date picker
100input field.
101
102```
103now | htmlDate
104```
105
106## htmlDateInZone
107
108Same as htmlDate, but with a timezone.
109
110```
111htmlDateInZone (now) "UTC"
112```
113
114## toDate, mustToDate
115
116`toDate` converts a string to a date. The first argument is the date layout and
117the second the date string. If the string can't be convert it returns the zero
118value.
119`mustToDate` will return an error in case the string cannot be converted.
120
121This is useful when you want to convert a string date to another format
122(using pipe). The example below converts "2017-12-31" to "31/12/2017".
123
124```
125toDate "2006-01-02" "2017-12-31" | date "02/01/2006"
126```
View as plain text