<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to STRING_TO_DATE function exception</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f33c3b1bc2/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f33c3b1bc2/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/f33c3b1bc2/</id><updated>2020-02-27T14:08:12.028000Z</updated><subtitle>Recent posts to STRING_TO_DATE function exception</subtitle><entry><title>STRING_TO_DATE function exception</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f33c3b1bc2/?limit=25#08cd" rel="alternate"/><published>2020-02-27T14:08:12.028000Z</published><updated>2020-02-27T14:08:12.028000Z</updated><author><name>mjuzwiak</name><uri>https://forge.codesys.com/u/mjuzwiak/</uri></author><id>https://forge.codesys.com7428ee1456bd5965b63baea58290d9c1f0184c76</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Other option is to manually check if passed string is matching required format:&lt;br/&gt;
1. Prepare function to check if single character in string is a character number (return true/false)&lt;br/&gt;
2. Prepare function to check if character is dash (return true/false)&lt;br/&gt;
3. Run this functions for all characters, one by one&lt;br/&gt;
4. If at least one call return false, do not perform conversion&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>STRING_TO_DATE function exception</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f33c3b1bc2/?limit=25#3aae" rel="alternate"/><published>2020-02-27T14:08:11.660000Z</published><updated>2020-02-27T14:08:11.660000Z</updated><author><name>e.kislov</name><uri>https://forge.codesys.com/u/e-kislov/</uri></author><id>https://forge.codesys.com3f78751e10334c078bfabbbe1d15a554c747e247</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi. You can use FSTRING_TO_DT from OSCAT library (with additional TO_DATE conversion).&lt;br/&gt;
&lt;a class="" href="https://store.codesys.com/oscat-basic.html" rel="nofollow"&gt;https://store.codesys.com/oscat-basic.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In case of invalid input string (like 'End Date') you just got 'NULL' date (1970-1-1) without any exception.&lt;/p&gt;
&lt;p&gt;&lt;img alt="IMG: 28" rel="nofollow" src="https://forum.codesys.com//download/file.php?id=4551"/&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>STRING_TO_DATE function exception</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f33c3b1bc2/?limit=25#356b" rel="alternate"/><published>2020-02-27T14:08:11.158000Z</published><updated>2020-02-27T14:08:11.158000Z</updated><author><name>tvm</name><uri>https://forge.codesys.com/u/tvm/</uri></author><id>https://forge.codesys.com61a16416ee5c0ba7498d704d718158135c3b44c5</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;using the STRING_TO_DATE function, I have found that an improperly formatted string could cause an Access Violation exception in the program.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="nt"&gt;DateAsString&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt;  &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="nt"&gt;STRING&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="s1"&gt;'2019-03-04'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="nt"&gt;DateAsDate&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt;  &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="nt"&gt;DATE&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="nt"&gt;DateAsDate&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;STRING_TO_DATE&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;CONCAT&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'DATE#'&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;DateAsString&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The above code works as expected, however if DateAsString becomes 'End Date', the function receives a string that looks like 'DATE#End Date', and will cause an exception.&lt;/p&gt;
&lt;p&gt;Is there any way to pre-validate the string before converting it?&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>