Question:
how can I add a number to another number contained into a variable?
1 2 3 |
$t0 = Get-date -UFormat "%H%M" $t1 = $t0 + 10 |
so, if $t0 is 1030, I would $t1 values 1040.
Answer:
force to [int]
before assign value to $t0 ( get-date -uformat
returns [string] type ):
1 2 3 |
[int]$t0 = Get-date -UFormat "%H%M" $t1 = $t0 + 10 |
if you change the order the coercing feature of powershell gives the expected value:
1 2 3 |
$t0 = Get-date -UFormat "%H%M" $t1 = 10 + $t0 |
because second operand is cast to type of first one