github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/docs/mkarray/date.md (about) 1 # Calendar Date Ranges 2 3 > Create arrays of dates 4 5 ## Description 6 7 Unlike bash, Murex also supports date ranges: 8 9 ``` 10 » a [25-dec-2020..05-jan-2021] 11 » a [..25-dec-2020] 12 » a [25-dec-2020..] 13 ``` 14 15 Please refer to [a (mkarray)](../commands/a.md) for more detailed usage of mkarray. 16 17 ## Usage 18 19 ``` 20 a: [start..end] -> <stdout> 21 a: [start..end,start..end] -> <stdout> 22 a: [start..end][start..end] -> <stdout> 23 ``` 24 25 All usages also work with `ja` and `ta` as well, eg: 26 27 ``` 28 ja: [start..end] -> <stdout> 29 ta: data-type [start..end] -> <stdout> 30 ``` 31 32 You can also inline arrays with the `%[]` syntax, eg: 33 34 ``` 35 %[start..end] 36 ``` 37 38 ## Examples 39 40 ``` 41 » a [25-Dec-2020..01-Jan-2021] 42 25-Dec-2020 43 26-Dec-2020 44 27-Dec-2020 45 28-Dec-2020 46 29-Dec-2020 47 30-Dec-2020 48 31-Dec-2020 49 01-Jan-2021 50 ``` 51 52 ``` 53 » a [31-Dec..25-Dec] 54 31-Dec 55 30-Dec 56 29-Dec 57 28-Dec 58 27-Dec 59 26-Dec 60 25-Dec 61 ``` 62 63 ## Detail 64 65 ### Current Date 66 67 If the start value is missing (eg `[..01-Jan-2020]`) then mkarray (`a` et al) 68 will start the range from the current date and count up or down to the end. 69 70 If the end value is missing (eg `[01-Jan-2020..]`) then mkarray will start at 71 the start value, as usual, and count up or down to the current date. 72 73 For example, if today was 25th December 2020: 74 75 ``` 76 » a [23-December-2020..] 77 23-December-2020 78 24-December-2020 79 25-December-2020 80 ``` 81 82 ``` 83 » a [..23-December-2020] 84 25-December-2020 85 24-December-2020 86 23-December-2020 87 ``` 88 89 This can lead so some fun like countdowns: 90 91 ``` 92 » out "${a: [..01-January-2021] -> len -> =-1} days until the new year!" 93 7 days until the new year! 94 ``` 95 96 ### Case Sensitivity 97 98 Date ranges are case aware. If the ranges are uppercase then the return will be 99 uppercase. If the ranges are title case (capital first letter) then the return 100 will be in title case. 101 102 #### lower case 103 104 ``` 105 » a [01-jan..03-jan] 106 01-jan 107 02-jan 108 03-jan 109 ``` 110 111 #### Title Case 112 113 ``` 114 » a [01-Jan..03-Jan] 115 01-Jan 116 02-Jan 117 03-Jan 118 ``` 119 120 #### UPPER CASE 121 122 ``` 123 » a [01-JAN..03-JAN] 124 01-JAN 125 02-JAN 126 03-JAN 127 ``` 128 129 ### Supported Date Formatting 130 131 Below is the source for the supported formatting options for date ranges: 132 133 ```go 134 package mkarray 135 136 var dateFormat = []string{ 137 // dd mm yy 138 139 "02-Jan-06", 140 "02-January-06", 141 "02-Jan-2006", 142 "02-January-2006", 143 144 "02 Jan 06", 145 "02 January 06", 146 "02 Jan 2006", 147 "02 January 2006", 148 149 "02/Jan/06", 150 "02/January/06", 151 "02/Jan/2006", 152 "02/January/2006", 153 154 // mm dd yy 155 156 "Jan-02-06", 157 "January-02-06", 158 "Jan-02-2006", 159 "January-02-2006", 160 161 "Jan 02 06", 162 "January 02 06", 163 "Jan 02 2006", 164 "January 02 2006", 165 166 "Jan/02/06", 167 "January/02/06", 168 "Jan/02/2006", 169 "January/02/2006", 170 171 // dd mm 172 173 "02-Jan", 174 "02-January", 175 176 "02 Jan", 177 "02 January", 178 179 "02/Jan", 180 "02/January", 181 } 182 ``` 183 184 If you do need any other formatting options not supported there, you can use 185 `datetime` to convert the output of `a`. eg: 186 187 ``` 188 » a [01-Jan-2020..03-Jan-2020] -> foreach { -> datetime --in "{go}02-Jan-2006" --out "{py}%A, %d %B"; echo } 189 Wednesday, 01 January 190 Thursday, 02 January 191 Friday, 03 January 192 ``` 193 194 ## See Also 195 196 * [Special Ranges](../mkarray/special.md): 197 Create arrays from ranges of dictionary terms (eg weekdays, months, seasons, etc) 198 * [`[ ..Range ]`](../parser/range.md): 199 Outputs a ranged subset of data from STDIN 200 * [`[[ Element ]]`](../parser/element.md): 201 Outputs an element from a nested structure 202 * [`a` (mkarray)](../commands/a.md): 203 A sophisticated yet simple way to build an array or list 204 * [`count`](../commands/count.md): 205 Count items in a map, list or array 206 * [`datetime`](../commands/datetime.md): 207 A date and/or time conversion tool (like `printf` but for date and time values) 208 * [`ja` (mkarray)](../commands/ja.md): 209 A sophisticated yet simply way to build a JSON array 210 * [`mtac`](../commands/mtac.md): 211 Reverse the order of an array 212 * [`ta` (mkarray)](../commands/ta.md): 213 A sophisticated yet simple way to build an array of a user defined data-type 214 * [index](../parser/item-index.md): 215 Outputs an element from an array, map or table 216 217 <hr/> 218 219 This document was generated from [builtins/core/mkarray/ranges_doc.yaml](https://github.com/lmorg/murex/blob/master/builtins/core/mkarray/ranges_doc.yaml).