{"id":236,"date":"2007-12-14T14:00:00","date_gmt":"2007-12-14T22:00:00","guid":{"rendered":"http:\/\/testblog.sapien.com\/index.php\/2007\/12\/14\/when-will-that-happen\/"},"modified":"2007-12-14T14:00:00","modified_gmt":"2007-12-14T22:00:00","slug":"when-will-that-happen","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2007\/12\/14\/when-will-that-happen\/","title":{"rendered":"When Will That Happen?"},"content":{"rendered":"<p>The other day I showed you how I wrapped the <strong>DateDiff<\/strong> function into my own function so that I wouldn&#8217;t have to remember that &#8220;n&#8221; is for minutes, among other things. Well the <strong>DateAdd<\/strong> function uses the same constants so it only makes sense to use a wrapper function here as well.<\/p>\n<p><font size=\"2\" face=\"Courier New\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">Function GetDateAdd(dtStart,iInterval,sInterval)<br \/>&#8217; Valid interval values are:<br \/>&#8217; Months,Days,Minutes,Hours,Seconds and they <br \/>&#8217; are not case sensitive <\/font> <\/p>\n<p><font size=\"2\" face=\"Courier New\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">&nbsp;&nbsp;&nbsp; Select Case LCase(sInterval)<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case &#8220;months&#8221; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result = DateAdd(&#8220;M&#8221;,iInterval,dtStart) <\/font> <\/p>\n<p><font size=\"2\" face=\"Courier New\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case &#8220;days&#8221;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result = DateAdd(&#8220;d&#8221;,iInterval,dtStart) <\/font> <\/p>\n<p><font size=\"2\" face=\"Courier New\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case &#8220;minutes&#8221;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result = DateAdd(&#8220;n&#8221;,iInterval,dtStart) <\/font> <\/p>\n<p><font size=\"2\" face=\"Courier New\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case &#8220;hours&#8221;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result = DateAdd(&#8220;h&#8221;,iInterval,dtStart) <\/font> <\/p>\n<p><font size=\"2\" face=\"Courier New\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case &#8220;seconds&#8221;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result = DateAdd(&#8220;s&#8221;,iInterval,dtStart)<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case Else result=&#8221;Unknown interval&#8221; <\/font> <\/p>\n<p><font size=\"2\" face=\"Courier New\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">&nbsp;&nbsp;&nbsp; End Select<br \/>&nbsp;&nbsp;&nbsp; GetDateAdd=result <\/font> <\/p>\n<p><font size=\"2\" face=\"Courier New\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">End Function<\/font> <\/p>\n<p>The form should look very similar to you if you read my last post. This function will return a calculated date time in the specified interval:<\/p>\n<p><font size=\"2\" face=\"Courier New\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">dtNow=Now<br \/>i=7 <\/font> <\/p>\n<p><font size=\"2\" face=\"Courier New\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">WScript.Echo &#8220;The date\/time from &#8221; &amp; dtNow &amp; &#8221; in:&#8221;<br \/>WScript.Echo i &amp; &#8221; Months:&nbsp; &#8221; &amp; GetDateAdd(dtNow,i,&#8221;months&#8221;)<br \/>WScript.Echo i &amp; &#8221; Days:&nbsp;&nbsp;&nbsp; &#8221; &amp; GetDateAdd(dtNow,i,&#8221;days&#8221;)<br \/>WScript.Echo i &amp; &#8221; Hours:&nbsp;&nbsp; &#8221; &amp; GetDateAdd(dtNow,i,&#8221;hours&#8221;)<br \/>WScript.Echo i &amp; &#8221; Minutes: &#8221; &amp; GetDateAdd(dtNow,i,&#8221;minutes&#8221;)<br \/>WScript.Echo i &amp; &#8221; Seconds: &#8221; &amp; GetDateAdd(dtNow,i,&#8221;seconds&#8221;)<\/font> <\/p>\n<p>You can also use a negative number to calculate a past date\/time value.<\/p>\n<p>Again, I&#8217;ve attached a text file with the code so you don&#8217;t have to copy and paste. <\/p>\n<div style=\"margin: 0px; padding: 0px; display: inline;\" id=\"scid:0767317B-992E-4b12-91E0-4F059A8CECA8:10a985d0-eb4e-4a17-8cc8-e5c8aa29f6a3\" class=\"wlWriterSmartContent\">Technorati Tags: <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/VBScript\">VBScript<\/a>, <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/Scripting\">Scripting<\/a>, <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/Functions\">Functions<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The other day I showed you how I wrapped the DateDiff function into my own function so that I wouldn&#8217;t have to remember that &#8220;n&#8221; is for minutes, among other things. Well the DateAdd function uses the same constants so it only makes sense to use a wrapper function here as well.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[24],"tags":[],"class_list":["post-236","post","type-post","status-publish","format-standard","hentry","category-vbscript"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/236","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=236"}],"version-history":[{"count":0,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/236\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}