<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.infopathdev.com:443/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>General</title><link>https://www.infopathdev.com:443/forums/41.aspx</link><description>If you're not sure where to ask your question, ask it here. If necessary, our moderators will make sure it gets classified in the correct board.</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>Re: Date range validation using less code</title><link>https://www.infopathdev.com:443/forums/thread/39180.aspx</link><pubDate>Wed, 04 Mar 2009 18:17:33 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:39180</guid><dc:creator>Alec Pojidaev</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/39180.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=41&amp;PostID=39180</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/infopathdev/images/icon-quote.gif"&gt; &lt;strong&gt;10basetom:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;I&amp;#39;ve read more than one article about date range validation that relied on too much code for my taste&lt;/div&gt;&lt;/BLOCKQUOTE&gt; 
&lt;p&gt;&amp;nbsp;So you might find that codeless solution even more satisfying: 
&lt;p&gt;&amp;nbsp;&lt;a href="http://alecpojidaev.wordpress.com/2008/12/30/infopath-codeless-programming-walkthrough-2/"&gt;http://alecpojidaev.wordpress.com/2008/12/30/infopath-codeless-programming-walkthrough-2/&lt;/a&gt; 
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Date range validation using less code</title><link>https://www.infopathdev.com:443/forums/thread/26152.aspx</link><pubDate>Fri, 01 Feb 2008 06:51:50 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:26152</guid><dc:creator>Patrick Halstead</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/26152.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=41&amp;PostID=26152</wfw:commentRss><description>&lt;p&gt;Thanks for sharing! &lt;/p&gt;</description></item><item><title>Date range validation using less code</title><link>https://www.infopathdev.com:443/forums/thread/26149.aspx</link><pubDate>Fri, 01 Feb 2008 06:41:50 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:26149</guid><dc:creator>10basetom</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/26149.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=41&amp;PostID=26149</wfw:commentRss><description>I&amp;#39;ve read more than one article about date range validation that relied on too much code for my taste, so I wrote simpler validation code that basically mimics how Excel calculates date ranges.&amp;nbsp;This seems to be working without a hitch so far. 
&lt;p&gt;Let&amp;#39;s assume you have two date fields: &lt;font face="courier new,courier"&gt;&lt;strong&gt;start_date&lt;/strong&gt;&lt;/font&gt; and &lt;strong&gt;&lt;font face="courier new,courier"&gt;end_date&lt;/font&gt;&lt;/strong&gt;. You want to ensure that &lt;font face="Courier New"&gt;end_date&lt;/font&gt; is at least 10 days after &lt;font face="Courier New"&gt;start_date&lt;/font&gt;, and of course you want this validation to work on leap years as well. In order for this date range validation to work, you&amp;#39;ll need to create a third, hidden field that will contain the difference in days between &lt;font face="Courier New"&gt;start_date&lt;/font&gt; and &lt;font face="courier new,courier"&gt;end_date&lt;/font&gt;; let&amp;#39;s call&amp;nbsp;this field&amp;nbsp;&lt;strong&gt;&lt;font face="courier new,courier"&gt;diff&lt;/font&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;When &lt;font face="Courier New"&gt;start_date&lt;/font&gt; is entered, you convert this date string into a JavaScript date serial number, which is similar to an Excel date serial number but is the number of milliseconds since 1/1/1970. If the end date serial number is already defined, then calculate the difference in days and output it to the &lt;font face="courier new,courier"&gt;diff&lt;/font&gt; field. Write a similar OnAfterChange event handler for &lt;font face="Courier New"&gt;end_date&lt;/font&gt;. Once the &lt;font face="Courier New"&gt;diff&lt;/font&gt; field is populated, then you can use InfoPath&amp;#39;s built-in data validation to ensure that the date range is at least ten days or whatever you want it to be.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s the complete code:&lt;/p&gt;
&lt;p&gt;&lt;font style="BACKGROUND-COLOR:#ffff66;" face="courier new,courier"&gt;var nDateStart, nDateEnd;&lt;br /&gt;var oDiff = XDocument.DOM.selectSingleNode(&amp;#39;my:myFields/my:diff&amp;#39;);&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font style="BACKGROUND-COLOR:#ffff66;" face="courier new,courier"&gt;function msoxd_my_start_date::OnAfterChange(eventObj) {&lt;br /&gt;&amp;nbsp; var str = eventObj.Site.text;&lt;br /&gt;&amp;nbsp; if (str) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Normalize date format (yyyy-mm-dd -&amp;gt; mm-dd-yyyy)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; nDateStart = Date.parse(str.replace(/(\d{4})-(.+)/,&amp;#39;$2-$1&amp;#39;));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (nDateEnd) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Calculate difference (86400000 milliseconds = 1 day)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; oDiff.text = (nDate2-nDate1)/86400000;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font style="BACKGROUND-COLOR:#ffff66;" face="courier new,courier"&gt;function msoxd_my_end_date::OnAfterChange(eventObj) {&lt;br /&gt;&amp;nbsp; var str = eventObj.Site.text;&lt;br /&gt;&amp;nbsp; if (str) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Normalize date format (yyyy-mm-dd -&amp;gt; mm-dd-yyyy)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; nDateEnd = Date.parse(str.replace(/(\d{4})-(.+)/,&amp;#39;$2-$1&amp;#39;));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (nDateStart) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Calculate difference (86400000 milliseconds = 1 day)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; oDiff.text = (nDate2-nDate1)/86400000;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Cheers,&lt;br /&gt;Tom&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; If you want to count just business days, then read my other post, &lt;a class="" href="http://www.infopathdev.com/forums/t/7156.aspx" target="_blank"&gt;How to calculate business days&lt;/a&gt;. Even if you don&amp;#39;t care about business days, the later post contains slightly improved code than what you see here.&lt;/p&gt;</description></item></channel></rss>