-
Notifications
You must be signed in to change notification settings - Fork 6
/
DateUtils.xml
287 lines (287 loc) · 12.2 KB
/
DateUtils.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<?xml version="1.0" encoding="utf-8"?>
<!-- This file along with its dll needs to be installed to ...InstallDir...\RuntimeData\FormulaAddIn to run. -->
<!-- Is Culture Specific as Uses names of weekdays -->
<FormulaAddIn>
<Function>
<Name>YEAR</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>Year(dt)</InsertText>
<Description>Get year of Date</Description>
<Formula>ToNumber(Left(P1, 4))</Formula>
</Function>
<Function>
<Name>CENTURY</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>Century(dt)</InsertText>
<Description>Get century of Date</Description>
<Formula>FLOOR(YEAR(P1)/100)+1</Formula>
</Function>
<Function>
<Name>MONTH</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>Month(dt)</InsertText>
<Description>Get month (1-12) of Date</Description>
<Formula>ToNumber(Substring(P1, 5, 2))</Formula>
</Function>
<Function>
<Name>DAY</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>Day(dt)</InsertText>
<Description>Get day of month (1-31) of Date</Description>
<Formula>ToNumber(Substring(P1, 8, 2))</Formula>
</Function>
<Function>
<Name>HOUR</Name>
<NumParams variable="false">1</NumParams>
<Category>Time</Category>
<InsertText>Hour(dt)</InsertText>
<Description>Get time of a datetime or a time</Description>
<Formula>ToNumber(Substring(P1, IIF(LENGTH(P1)=8, 0, 11), 2))</Formula>
</Function>
<Function>
<Name>MINUTE</Name>
<NumParams variable="false">1</NumParams>
<Category>Time</Category>
<InsertText>Minute(dt)</InsertText>
<Description>Get time of a datetime or a time</Description>
<Formula>ToNumber(Substring(P1, IIF(LENGTH(P1)=8, 3, 14), 2))</Formula>
</Function>
<Function>
<Name>SECOND</Name>
<NumParams variable="false">1</NumParams>
<Category>Time</Category>
<InsertText>Second(dt)</InsertText>
<Description>Get time of a datetime or a time</Description>
<Formula>ToNumber(Substring(P1, IIF(LENGTH(P1)=8, 6, 17), 2))</Formula>
</Function>
<Function>
<Name>WEEKDAY</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>Weekday(dt)</InsertText>
<Description>Convert a date to day of week (0 Sunday - 6 Saturday)</Description>
<Formula>IIF(VERSION()>=11,ToNumber(DateTimeFormat(P1, "%w")),Switch(DateTimeFormat(P1,"%a"),NULL(),"Sun",0,"Mon",1,"Tue",2,"Wed",3,"Thu",4,"Fri",5,"Sat",6))</Formula>
</Function>
<Function>
<Name>WORKDAY</Name>
<NumParams variable="false">2</NumParams>
<Category>Date</Category>
<InsertText>Workday(dt,days)</InsertText>
<Description>Returns the date after a specified number of week days</Description>
<Formula>IIF(P2=0,P1,DATETIMEADD(P1,FLOOR(ABS(P2)/5)*SIGN(P2)*7+IIF(WEEKDAY(P1)=0,IIF(P2>0,-2,1),0)+IIF(WEEKDAY(P1)=6,IIF(P2>0,-1,2),0)+IIF(MOD(P2,5)=0,0,MOD(P2,5)+IIF(P2>0,IIF(IIF(WEEKDAY(P1)=0,7,WEEKDAY(P1))+MOD(P2,5)>5,2,0),IIF(WEEKDAY(P1) IN (0,6) OR (WEEKDAY(P1)+MOD(P2,5))<1,-2,0))),"days"))</Formula>
</Function>
<Function>
<Name>QUARTER</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>Quarter(dt)</InsertText>
<Description>Convert date to quarter</Description>
<Formula>FLOOR((MONTH(P1)+2)/3)</Formula>
</Function>
<Function>
<Name>ISLEAPYEAR</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>IsLeapYear(Year)</InsertText>
<Description>Is a year a leap year</Description>
<Formula>(MOD(P1, 4) == 0) AND (MOD(P1, 100) != 0 OR MOD(P1, 400) == 0)</Formula>
</Function>
<Function>
<Name>ORDINALDAY</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>OrdinalDay(dt)</InsertText>
<Description>The position within the year</Description>
<Formula>ToNumber(DateTimeFormat(P1, "%j"))</Formula>
</Function>
<Function>
<Name>MAKEDATE</Name>
<NumParams variable="true">1</NumParams>
<Category>Date</Category>
<InsertText>MakeDate(Year, Month, Day)</InsertText>
<Description>Create a Date</Description>
<Dll>
<Name>AlteryxAbacus.dll</Name>
<EntryPoint>MakeDate</EntryPoint>
</Dll>
</Function>
<Function>
<Name>MAKETIME</Name>
<NumParams variable="true">0</NumParams>
<Category>Time</Category>
<InsertText>MakeTime(Hour, Minute, Second)</InsertText>
<Description>Create a Time</Description>
<Dll>
<Name>AlteryxAbacus.dll</Name>
<EntryPoint>MakeTime</EntryPoint>
</Dll>
</Function>
<Function>
<Name>MAKEDATETIME</Name>
<NumParams variable="false">6</NumParams>
<Category>DateTime</Category>
<InsertText>MakeDateTime(Year, Month, Day, Hour, Minute, Second)</InsertText>
<Description>Create a DateTime</Description>
<Formula>MAKEDATE(P1,P2,P3) + ' ' + MAKETIME(P4,P5,P6)</Formula>
</Function>
<Function>
<Name>TODATE</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>ToDate(dt)</InsertText>
<Description>Truncates a datetime and returns as a Date</Description>
<Formula>IIF(LENGTH(P1) = 10, P1, IIF(LENGTH(P1) = 19, LEFT(P1, 10), NULL()))</Formula>
</Function>
<Function>
<Name>TODATETIME</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>ToDateTime(dt)</InsertText>
<Description>Appends midnight to a date and returns a datetime</Description>
<Formula>IIF(LENGTH(P1) = 19, P1, IIF(LENGTH(P1) = 10, P1 + ' 00:00:00', NULL()))</Formula>
</Function>
<Function>
<Name>TOTIME</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>ToTime(dt)</InsertText>
<Description>Extracts Time from a DateTime or Date</Description>
<Formula>IIF(LENGTH(P1) = 19, RIGHT(P1,8), IIF(LENGTH(P1) = 10, '00:00:00', IIF(LENGTH(P1) = 8, P1, NULL())))</Formula>
</Function>
<Function>
<Name>DATEADD</Name>
<NumParams variable="false">3</NumParams>
<Category>Date</Category>
<InsertText>DateAdd(Date,i,u)</InsertText>
<Description>Add a specific interval to a date/time and returns as a Date. DateAdd([Date], -3, "days")</Description>
<Formula>Left(DateTimeAdd(P1, P2, P3), 10)</Formula>
</Function>
<Function>
<Name>BUSINESSDAYS</Name>
<NumParams variable="false">2</NumParams>
<Category>Date</Category>
<InsertText>BusinessDays(StartDate, EndDate)</InsertText>
<Description>Number of business days (M-F) between two dates.</Description>
<Formula>IIF(P1>P2,NULL(), 1 + ((DateTimeDiff(P2,P1,"days")*5 - (WEEKDAY(P1)-WEEKDAY(P2))*2) / 7) + IIF(WEEKDAY(P2)==6,-1,0) + IIF(WEEKDAY(P1)==0,-1,0))</Formula>
</Function>
<Function>
<Name>WEEKNUM</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>WeekNum(dt)</InsertText>
<Description>The week number with Sunday as start of week and January 1st in Week 1 (1-53)</Description>
<Formula>CEIL((DateTimeDiff(P1, WEEKSTART(LEFT(P1,4) + "-01-01"), "days") + 1) / 7)</Formula>
</Function>
<Function>
<Name>WEEKSTART</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>WeekStart(dt)</InsertText>
<Description>Move to First day of the week (Sunday)</Description>
<Formula>DateAdd(P1, 0 - WEEKDAY(P1), "days")</Formula>
</Function>
<Function>
<Name>WEEKEND</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>WeekEnd(dt)</InsertText>
<Description>Move to Last day of the week (Saturday)</Description>
<Formula>DateAdd(P1, 6 - WEEKDAY(P1), "days")</Formula>
</Function>
<Function>
<Name>MONTHSTART</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>MonthStart(dt)</InsertText>
<Description>Create the first day of the month</Description>
<Formula>LEFT(P1,8) + "01"</Formula>
</Function>
<Function>
<Name>MONTHEND</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>MonthEnd(dt)</InsertText>
<Description>Create the last day of the month</Description>
<Formula>DATEADD(DATEADD(LEFT(P1,8) + "01", 1, "Months"), -1, "Days")</Formula>
</Function>
<Function>
<Name>QUARTERSTART</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>QuarterStart(dt)</InsertText>
<Description>Create the first day of the quarter</Description>
<Formula>LEFT(P1,5) + RIGHT("00" + TOSTRING(QUARTER(P1) * 3 - 2, 0), 2) + "-01"</Formula>
</Function>
<Function>
<Name>QUARTEREND</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>QuarterEnd(dt)</InsertText>
<Description>Create the last day of the quarter</Description>
<Formula>MONTHEND(LEFT(P1,5) + RIGHT("00" + TOSTRING(QUARTER(P1) * 3, 0), 2) + "-01")</Formula>
</Function>
<Function>
<Name>YEARSTART</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>YearStart(dt)</InsertText>
<Description>Create the first day of the year</Description>
<Formula>LEFT(P1,5) + "01-01"</Formula>
</Function>
<Function>
<Name>YEAREND</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>YearEnd(dt)</InsertText>
<Description>Create the last day of the year</Description>
<Formula>LEFT(P1,5) + "12-31"</Formula>
</Function>
<Function>
<Name>DATEFROMMDY</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>DateFromMDY(MDY)</InsertText>
<Description>Parse a M/D/Y date string into Alteryx format. Copes with or without leading 0 and with various separators.</Description>
<Formula>DATETIMEPARSE(REGEX_Replace(Trim(REGEX_Replace(" " + P1,"(\D)(\d)(?=\D)","${1}0$2")), "\D", "/"), "%m/%d/" + IIF(REGEX_Match(P1,".*\D\d{1,2}$"), "%y", "%Y"))</Formula>
</Function>
<Function>
<Name>DATEFROMDMY</Name>
<NumParams variable="false">1</NumParams>
<Category>Date</Category>
<InsertText>DateFromDMY(DMY)</InsertText>
<Description>Parse a D/M/Y date string into Alteryx format. Copes with or without leading 0 and with various separators.</Description>
<Formula>DATETIMEPARSE(REGEX_Replace(Trim(REGEX_Replace(" " + P1,"(\D)(\d)(?=\D)","${1}0$2")), "\D", "/"), "%d/%m/" + IIF(REGEX_Match(P1,".*\D\d{1,2}$"), "%y", "%Y"))</Formula>
</Function>
<Function>
<Name>DATEPART</Name>
<NumParams variable="false">2</NumParams>
<Category>DateTime</Category>
<InsertText>DatePart(interval, dt)</InsertText>
<Description>Reproduces SQL Server's DatePart function. Support SQL servers standard parts as well as the numeric Alteryx date formatters.</Description>
<Formula>IF ISNULL(P1) OR ISNULL(P2) THEN NULL()
ELSEIF LOWERCASE(P1) IN ("century", "cc", "c") THEN Century(P2)
ELSEIF P1 = "%C" THEN Century(P2)-1
ELSEIF P1 = "%y" AND CHARTOINT(RIGHT(P1,1))=121 THEN MOD(YEAR(P2),100)
ELSEIF LOWERCASE(P1) IN ("year", "yyyy", "yy", "%y") THEN Year(P2)
ELSEIF LOWERCASE(P1) IN ("quarter","qq","q") THEN Quarter(P2)
ELSEIF LOWERCASE(P1) IN ("month","mm","m") THEN Month(P2)
ELSEIF P1 = "%m" AND CHARTOINT(RIGHT(P1,1))=109 THEN MONTH(P2)
ELSEIF LOWERCASE(P1) IN ("dayofyear","dy","y","%j") THEN OrdinalDay(P2)
ELSEIF LOWERCASE(P1) IN ("day","dd","d","%d","%e") THEN Day(P2)
ELSEIF LOWERCASE(P1) IN ("weekday","dw","w") THEN Weekday(P2)
ELSEIF P1 = "%w" AND CHARTOINT(RIGHT(P1,1))=119 THEN Weekday(P2)
ELSEIF P1 = "%u" AND CHARTOINT(RIGHT(P1,1))=117 THEN IIF(Weekday(P2)=0,7,Weekday(P2))
ELSEIF LOWERCASE(P1) IN ("week","ww","wk") THEN Weeknum(P2)
ELSEIF LOWERCASE(P1) IN ("%u") THEN Weeknum(P2)-IIF(Weekday(YearStart(P2))=0,0,1)
ELSEIF LOWERCASE(P1) IN ("%w") THEN TONUMBER(DATETIMEFORMAT(P2,"%W"))
ELSEIF LOWERCASE(P1) IN ("hour","hh","h","%h","%k") THEN Hour(P2)
ELSEIF LOWERCASE(P1) IN ("%i","%l") THEN IIF(MOD(Hour(P2),12)=0, 12, MOD(Hour(P2),12))
ELSEIF LOWERCASE(P1) IN ("minute","mi","n","%m") THEN Minute(P2)
ELSEIF LOWERCASE(P1) IN ("second","ss","s","%s") THEN Second(P2)
ELSE NULL() ENDIF</Formula>
</Function>
</FormulaAddIn>