powershell - Integers are not adding / subtracting -


i reading data database , value in question date , time stamp.

to keep things short data similar this. 7/24/2015 16:13:58

i extract date this.

$scandate = $($row[3]).tostring()         [string]$scan = $scandate.substring(0,10) 

i split $scandate array

$scan.split('/')

then change value integer each day, month , year

[int]$scanmonth = $scan[0] [int]$scanday = $scan[1] [int]$scanyear = $scan[2] 

check integers..

$scanday.gettype() $scanyear.gettype() $scanmonth.gettype() 

returns..

ispublic isserial name                                     basetype -------- -------- ----                                     -------- true     true     int32                                    system.valuetype true     true     int32                                    system.valuetype true     true     int32                                    system.valuetype 

the issue when try , add , subtract integers, getting wrong result?

$total = [int]$scanday + [int]$scanmonth write-host $total 

so values 24 + 7 come out 102 not 31.

what missing? appreciated :)

updated

ok wanted add final compare code..after being told database value interpreted powershell datetime this.

$date = get-date $date = $date.touniversaltime()  $daydifference = new-timespan -start $date -end $row[3] if ($daydifference.totaldays -gt 5) { 'do something' } 

$scan = "7/24/2015 16:13:58" $scan = $scan.split('/'); [int]$scanmonth = $scan[0] [int]$scanday = $scan[1] [int]$scanyear = ($scan[2].split())[0]  $total = [int]$scanday + [int]$scanmonth write-host $total 

then you'll 31.. although still think should using datetime object

update : easier way solve actual problem:

$scan = "7/24/2015 16:13:58" $scandate = [datetime]$scan $date = (get-date).adddays(-5) if($date -lt $scandate) {'do something'} 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -