{"id":8841,"date":"2007-01-08T23:43:00","date_gmt":"2007-01-08T23:43:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2007\/01\/08\/two-plus-two-equals-monday\/"},"modified":"2019-02-18T13:20:54","modified_gmt":"2019-02-18T20:20:54","slug":"two-plus-two-equals-monday","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/two-plus-two-equals-monday\/","title":{"rendered":"Two plus two equals &#034;Monday&#034; ?"},"content":{"rendered":"<p><!--\n \/* Font Definitions *\/\n @font-face\n\t{font-family:\"Cambria Math\";\n\tpanose-1:2 4 5 3 5 4 6 3 2 4;}\n@font-face\n\t{font-family:Cambria;\n\tpanose-1:2 4 5 3 5 4 6 3 2 4;}\n@font-face\n\t{font-family:Calibri;\n\tpanose-1:2 15 5 2 2 2 4 3 2 4;}\n@font-face\n\t{font-family:\"Lucida Console\";\n\tpanose-1:2 11 6 9 4 5 4 2 2 4;}\n \/* Style Definitions *\/\n p.MsoNormal, li.MsoNormal, div.MsoNormal\n\t{margin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:10.0pt;\n\tmargin-left:.75in;\n\tline-height:115%;\n\tfont-size:11.0pt;\n\tfont-family:\"Calibri\",\"sans-serif\";}\nh2\n\t{mso-style-link:\"Heading 2 Char\";\n\tmargin-top:10.0pt;\n\tmargin-right:0in;\n\tmargin-bottom:0in;\n\tmargin-left:.75in;\n\tmargin-bottom:.0001pt;\n\tline-height:115%;\n\tpage-break-after:avoid;\n\tfont-size:13.0pt;\n\tfont-family:\"Cambria\",\"serif\";\n\tcolor:#4F81BD;\n\tfont-weight:bold;}\na:link, span.MsoHyperlink\n\t{color:blue;\n\ttext-decoration:underline;}\na:visited, span.MsoHyperlinkFollowed\n\t{color:purple;\n\ttext-decoration:underline;}\np\n\t{margin-right:0in;\n\tmargin-left:0in;\n\tfont-size:12.0pt;\n\tfont-family:\"Times New Roman\",\"serif\";}\np.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph\n\t{margin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:10.0pt;\n\tmargin-left:.5in;\n\tline-height:115%;\n\tfont-size:11.0pt;\n\tfont-family:\"Calibri\",\"sans-serif\";}\nspan.Heading2Char\n\t{mso-style-name:\"Heading 2 Char\";\n\tmso-style-link:\"Heading 2\";\n\tfont-family:\"Cambria\",\"serif\";\n\tcolor:#4F81BD;\n\tfont-weight:bold;}\np.msolistparagraphcxspfirst, li.msolistparagraphcxspfirst, div.msolistparagraphcxspfirst\n\t{mso-style-name:msolistparagraphcxspfirst;\n\tmargin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:0in;\n\tmargin-left:.5in;\n\tmargin-bottom:.0001pt;\n\tline-height:115%;\n\tfont-size:11.0pt;\n\tfont-family:\"Calibri\",\"sans-serif\";}\np.msolistparagraphcxspmiddle, li.msolistparagraphcxspmiddle, div.msolistparagraphcxspmiddle\n\t{mso-style-name:msolistparagraphcxspmiddle;\n\tmargin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:0in;\n\tmargin-left:.5in;\n\tmargin-bottom:.0001pt;\n\tline-height:115%;\n\tfont-size:11.0pt;\n\tfont-family:\"Calibri\",\"sans-serif\";}\np.msolistparagraphcxsplast, li.msolistparagraphcxsplast, div.msolistparagraphcxsplast\n\t{mso-style-name:msolistparagraphcxsplast;\n\tmargin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:10.0pt;\n\tmargin-left:.5in;\n\tline-height:115%;\n\tfont-size:11.0pt;\n\tfont-family:\"Calibri\",\"sans-serif\";}\nspan.CodeChar\n\t{mso-style-name:\"Code Char\";\n\tmso-style-link:Code;\n\tfont-family:\"Lucida Console\";\n\tcolor:#EEEDF0;\n\tbackground:#012456;}\np.Code, li.Code, div.Code\n\t{mso-style-name:Code;\n\tmso-style-link:\"Code Char\";\n\tmargin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:12.0pt;\n\tmargin-left:.75in;\n\tline-height:115%;\n\tbackground:#012456;\n\tfont-size:8.0pt;\n\tfont-family:\"Lucida Console\";\n\tcolor:#EEEDF0;}\np.msopapdefault, li.msopapdefault, div.msopapdefault\n\t{mso-style-name:msopapdefault;\n\tmargin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:10.0pt;\n\tmargin-left:.75in;\n\tline-height:115%;\n\tfont-size:12.0pt;\n\tfont-family:\"Times New Roman\",\"serif\";}\n.MsoChpDefault\n\t{font-size:10.0pt;}\n@page Section1\n\t{size:8.5in 11.0in;\n\tmargin:1.0in 1.0in 1.0in 1.0in;}\ndiv.Section1\n\t{page:Section1;}\n--><\/p>\n<p>In PowerShell, two plus two does not always equal four.&nbsp; <\/p>\n<p>Why?&nbsp; Because there are twos and there are twos.<\/p>\n<p>Let me explain.&nbsp; PowerShell does a ton of work on your behalf so you can think about what you want to do and not how to do it.&nbsp; Think&nbsp;about the difference between an&nbsp;automatic transmission and a manual one.&nbsp; An automatic does a ton of work on your behalf but sometimes it doesn&#8217;t have the information to make the right decision.&nbsp; That is why automatic transmissions allow you to shift into 1, 2 ,3&nbsp; or D (which automatically shifts for you).&nbsp; Occassionally, you need to override the decision making.&nbsp; In the end, an automatic transmission is a pretty good deal.&nbsp; <\/p>\n<p>PowerShell is actually more like a tiptronic transmission (which is what I drive) which gives you the option of being automatic or manual giving you the best of both worlds..&nbsp; Most people don&#8217;t have experience with those so I&#8217;ll just go with the automatic analogy.&nbsp; <\/p>\n<p>So back to two plus two.&nbsp; Sometimes two is a string and sometimes it is an int.&nbsp; So, to steal a little from Tolstoy &#8211; when then must we do?&nbsp; <\/p>\n<p>What PowerShell does is to use the type of the first element of the expression to type the expression.&nbsp; If it is an number the addition is a numeric addition.&nbsp; If it is a String, the addition is a string addition.&nbsp; Ditto for multiplication.&nbsp; Let me show you:<\/p>\n<p class=\"Code\">PS&gt; 2+2<br \/>4<br \/>PS&gt; 2+&#8221;2&#8243;<br \/>4<br \/>PS&gt; &#8220;2&#8221;+&#8221;2&#8243;<br \/>22<br \/>PS&gt; &#8220;2&#8221;+2<br \/>22<br \/>PS&gt; 2 * 30<br \/>60<br \/>PS&gt; &#8220;2&#8221; * 30<br \/>222222222222222222222222222222<br \/>PS&gt; [Int]&#8221;2&#8243; + 2<br \/>4&nbsp;<br \/>PS&gt; [INT](&#8220;2&#8221; + 2)<br \/>22<br \/>PS&gt; [STRING]2 + 2<br \/>22<br \/>PS&gt; [INT]$x = &#8220;2&#8221;<br \/>PS&gt; $x + 2<br \/>4<\/p>\n<p>&nbsp;<\/p>\n<p>Got your head around that one yet?&nbsp; Try this one:<\/p>\n<p>&nbsp;<\/p>\n<p class=\"Code\">PS&gt; [timespan]2 + 2<\/p>\n<p>Days<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 0<br \/>Hours<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 0<br \/>Minutes<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 0<br \/>Seconds<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 0<br \/>Milliseconds<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 0<br \/>Ticks<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 4<br \/>TotalDays<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 4.62962962962963E-12<br \/>TotalHours<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 1.11111111111111E-10<br \/>TotalMinutes<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 6.66666666666667E-09<br \/>TotalSeconds<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 4E-07<br \/>TotalMilliseconds : 0.0004<\/p>\n<p>PS&gt; [DateTime]2 + 2<\/p>\n<p>Monday, January 01, 0001 12:00:00 AM<\/p>\n<p>&nbsp;<\/p>\n<p>I LOVE this&nbsp;stuff!&nbsp;<\/p>\n<p>Jeffrey Snover [MSFT]<br \/>Windows PowerShell\/MMC Architect<br \/>Visit the Windows PowerShell Team blog at:&nbsp;&nbsp;&nbsp; <a href=\"http:\/\/blogs.msdn.com\/PowerShell\">http:\/\/blogs.msdn.com\/PowerShell<\/a><br \/>Visit the Windows PowerShell ScriptCenter at:&nbsp; <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In PowerShell, two plus two does not always equal four.&nbsp; Why?&nbsp; Because there are twos and there are twos. Let me explain.&nbsp; PowerShell does a ton of work on your behalf so you can think about what you want to do and not how to do it.&nbsp; Think&nbsp;about the difference between an&nbsp;automatic transmission and a [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8841","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>In PowerShell, two plus two does not always equal four.&nbsp; Why?&nbsp; Because there are twos and there are twos. Let me explain.&nbsp; PowerShell does a ton of work on your behalf so you can think about what you want to do and not how to do it.&nbsp; Think&nbsp;about the difference between an&nbsp;automatic transmission and a [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/8841","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=8841"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/8841\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=8841"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=8841"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=8841"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}