{"id":200,"date":"2010-03-10T07:14:06","date_gmt":"2010-03-09T20:14:06","guid":{"rendered":"http:\/\/threemillion.net\/blog\/?p=200"},"modified":"2010-03-10T07:18:47","modified_gmt":"2010-03-09T20:18:47","slug":"add-one-minute-batch-vs-vbscript-vs-powershell","status":"publish","type":"post","link":"https:\/\/threemillion.net\/blog\/?p=200","title":{"rendered":"Add one minute Batch vs VBScript vs Powershell"},"content":{"rendered":"<p>Here is an interesting comparison between scripting languages. I was playing with getting the time 1 minute into the future in order to set up a scheduled command. So I needed the time to be in the following format: <strong>HH:MM<\/strong><br \/>\nSo since I was playing with the at.exe I figured a batch would be easy enough, surely. Well as it turns out, not so, as you can see from the code below a little more work than I expected was required. Now admittedly there may be other ways of doing this much better, man I sure hope so, however this is what I came up with.<\/p>\n<h2>Batch File<\/h2>\n<p>[cmd]<br \/>\n@ECHO OFF<br \/>\nECHO.<br \/>\nECHO Add x minute(s) to the current time<br \/>\nECHO.<\/p>\n<p>REM Only use minutes less than 60. or else the calculations fail.<br \/>\nSET \/A addmin=1<\/p>\n<p>SET nowtime=%time:~0,5%<br \/>\nSET \/A nowmin=%nowtime:~3,2%<br \/>\nSET \/A nowhour=%nowtime:~0,2%<\/p>\n<p>REM now add x minute(s) to the time<br \/>\nSET \/A nowmin=%nowmin%+%addmin%<\/p>\n<p>REM Future change: if gtr 60 divide by 60 to determine the number of hours to<br \/>\nREM add to the now hour variable. And the left over will be the minutes to add<br \/>\nREM then if the extra mins takes it over another hour, then add this as well.<br \/>\nIF %nowmin% GTR 59 (<br \/>\n  SET \/A nowmin=%nowmin%-60<br \/>\n  SET \/A nowhour=%nowhour%+1<br \/>\n)<\/p>\n<p>REM If nowhour has gone past 12<br \/>\nIF %nowhour% GTR 12 SET \/A nowhour=%nowhour%-12<\/p>\n<p>REM Test the value is less than 10 and add a leading zero<br \/>\nif %nowmin% LSS 10 (<br \/>\n  REM echo &#8220;Less than 10&#8221;<br \/>\n  SET nowmin=0%nowmin%<br \/>\n) else (<br \/>\n  REM echo &#8220;Higher than 10&#8221;<br \/>\n)<\/p>\n<p>SET thistime=%nowhour%:%nowmin%<br \/>\nECHO %nowtime%<br \/>\nECHO %thistime%<br \/>\n[\/cmd]<\/p>\n<p>Then I got to thinking, how would I do this in some other languages?<\/p>\n<h2>VBScript<\/h2>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nFormatDateTime(DateAdd(&quot;n&quot;, 1, Now()), VBShortTime)\r\n<\/pre>\n<h2>Powershell<\/h2>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nGet-Date((Get-Date).AddMinutes(1)) -Format 'HH:mm'\r\n<\/pre>\n<p>Significantly shorter coding in either of vbscript or powershell. Was to be expected really, however interesting none the less.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is an interesting comparison between scripting languages. I was playing with getting the time 1 minute into the future in order to set up a scheduled command. So I <a href=\"https:\/\/threemillion.net\/blog\/?p=200\" class=\"more-link\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[10,8,9],"tags":[],"class_list":["entry","author-admin","post-200","post","type-post","status-publish","format-standard","category-batch","category-powershell","category-vbscript"],"_links":{"self":[{"href":"https:\/\/threemillion.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/200","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/threemillion.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/threemillion.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/threemillion.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/threemillion.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=200"}],"version-history":[{"count":8,"href":"https:\/\/threemillion.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/200\/revisions"}],"predecessor-version":[{"id":254,"href":"https:\/\/threemillion.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/200\/revisions\/254"}],"wp:attachment":[{"href":"https:\/\/threemillion.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/threemillion.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/threemillion.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}