I am seeing if anyone has a solution for converting text to date that is in the following format 201909050425 within Arcade Expressions?
Hi Eric Shreve,
I think you could probably modify the Arcade expression found in this thread to convert the string to a date:
https://community.esri.com/thread/222378-text-to-date-using-arcade-expressions
Hope this helps,
Peter
Hi Eric Shreve ,
What is the format of the data? Is 201909050425 in YYYYMMDDHHmm format or is it perhaps YYYYDDMMHHmm?
In case it is first month and then day, it would be something like this (assuming the you are using military hours):
<SPAN class="comment token">// Date ( value , month , day , hour , minute , second , millisecond )</SPAN> <SPAN class="keyword token">var</SPAN> txt <SPAN class="operator token">=</SPAN> <SPAN class="string token">"201909050425"</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> YY <SPAN class="operator token">=</SPAN> <SPAN class="token function">Number</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">Mid</SPAN><SPAN class="punctuation token">(</SPAN>txt<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN> <SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> MM <SPAN class="operator token">=</SPAN> <SPAN class="token function">Number</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">Mid</SPAN><SPAN class="punctuation token">(</SPAN>txt<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN> <SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">-</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> DD <SPAN class="operator token">=</SPAN> <SPAN class="token function">Number</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">Mid</SPAN><SPAN class="punctuation token">(</SPAN>txt<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN> <SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> HH <SPAN class="operator token">=</SPAN> <SPAN class="token function">Number</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">Mid</SPAN><SPAN class="punctuation token">(</SPAN>txt<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN> <SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> mi <SPAN class="operator token">=</SPAN> <SPAN class="token function">Number</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">Right</SPAN><SPAN class="punctuation token">(</SPAN>txt<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// Console(YY);</SPAN> <SPAN class="comment token">// Console(MM);</SPAN> <SPAN class="comment token">// Console(DD);</SPAN> <SPAN class="comment token">// Console(HH);</SPAN> <SPAN class="comment token">// Console(mi);</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="token function">Date</SPAN><SPAN class="punctuation token">(</SPAN>YY<SPAN class="punctuation token">,</SPAN> MM<SPAN class="punctuation token">,</SPAN> DD<SPAN class="punctuation token">,</SPAN> HH<SPAN class="punctuation token">,</SPAN> mi<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Xander Bakker
It is formatted as YYYYMMDD. I switched the 'var txt' to 'VALID' which is the the field in the feature service and I am not able to get it working. Do you know what I am missing in the configuration?
// Date ( value , month , day , hour , minute , second , millisecond ) var txt = "VALID"; var YY = Number(Mid(txt, 0 , 4)); var MM = Number(Mid(txt, 4 , 2)) - 1; var DD = Number(Mid(txt, 6 , 2)); var HH = Number(Mid(txt, 8 , 2)); var mi = Number(Right(txt, 2)); // Console(YY); // Console(MM); // Console(DD); // Console(HH); // Console(mi); return Date(YY, MM, DD, HH, mi);<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Thanks,
Eric Shreve
Hi Eric Shreve
I don't think it is formatted as "YYYYMMDD" since you have more numbers, or are you only interested in the date and not the time?
In case your format is "YYYMMDDHHmm" you would use this:
<SPAN class="keyword token">var</SPAN> txt <SPAN class="operator token">=</SPAN> $feature<SPAN class="punctuation token">.</SPAN>VALID<SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// in case your field is called "VALID"</SPAN> <SPAN class="keyword token">var</SPAN> YY <SPAN class="operator token">=</SPAN> <SPAN class="token function">Number</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">Mid</SPAN><SPAN class="punctuation token">(</SPAN>txt<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN> <SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> MM <SPAN class="operator token">=</SPAN> <SPAN class="token function">Number</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">Mid</SPAN><SPAN class="punctuation token">(</SPAN>txt<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN> <SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">-</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> DD <SPAN class="operator token">=</SPAN> <SPAN class="token function">Number</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">Mid</SPAN><SPAN class="punctuation token">(</SPAN>txt<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN> <SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> HH <SPAN class="operator token">=</SPAN> <SPAN class="token function">Number</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">Mid</SPAN><SPAN class="punctuation token">(</SPAN>txt<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN> <SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> mi <SPAN class="operator token">=</SPAN> <SPAN class="token function">Number</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">Right</SPAN><SPAN class="punctuation token">(</SPAN>txt<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="token function">Date</SPAN><SPAN class="punctuation token">(</SPAN>YY<SPAN class="punctuation token">,</SPAN> MM<SPAN class="punctuation token">,</SPAN> DD<SPAN class="punctuation token">,</SPAN> HH<SPAN class="punctuation token">,</SPAN> mi<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
In case you are only interested in the date not the time, you would use this:
<SPAN class="keyword token">var</SPAN> txt <SPAN class="operator token">=</SPAN> $feature<SPAN class="punctuation token">.</SPAN>VALID<SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// in case your field is called "VALID"</SPAN> <SPAN class="keyword token">var</SPAN> YY <SPAN class="operator token">=</SPAN> <SPAN class="token function">Number</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">Mid</SPAN><SPAN class="punctuation token">(</SPAN>txt<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN> <SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> MM <SPAN class="operator token">=</SPAN> <SPAN class="token function">Number</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">Mid</SPAN><SPAN class="punctuation token">(</SPAN>txt<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN> <SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">-</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> DD <SPAN class="operator token">=</SPAN> <SPAN class="token function">Number</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">Mid</SPAN><SPAN class="punctuation token">(</SPAN>txt<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN> <SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="token function">Date</SPAN><SPAN class="punctuation token">(</SPAN>YY<SPAN class="punctuation token">,</SPAN> MM<SPAN class="punctuation token">,</SPAN> DD<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
How would I offset the time to local time?
I tried adding this line of code but it looks like it is not taking:
var pacificTime = DateAdd(ToUTC(Date), -7, "hours");
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.