# date calculation

## Recommended Posts

I'd like to calculate the date..

the format i have is . YYMMDD

is that any easy way just to subtract it by 1 day.....

e.g. 070501 - 1 ,, result = 070430

is there any method to convert YYMMDD to a format that can be calculated...

i don't want to have too many ''select,case' if then'' with YYMMDD

##### Share on other sites

I'd like to calculate the date..

the format i have is . YYMMDD

is that any easy way just to subtract it by 1 day.....

e.g. 070501 - 1 ,, result = 070430

is there any method to convert YYMMDD to a format that can be calculated...

i don't want to have too many ''select,case' if then'' with YYMMDD

So if the date was like this: 2007/05/08, then try this

```\$date = "2007/05/08"

\$datestrip = StringSplit (\$date, "/")

\$newdate = \$datestrip[1] & "/" & \$datestrip[2] & "/" & \$datestrip[3]-1

MsgBox (0, "Date Calc", "Old Date: "&\$date &@CRLF&"New Date: "&\$newdate)```

You can refine it. Give it ago, add a if statement, If you hit a wall, come ask for more help . Hope it helps.....

##### Share on other sites

So if the date was like this: 2007/05/08, then try this

```\$date = "2007/05/08"

\$datestrip = StringSplit (\$date, "/")

\$newdate = \$datestrip[1] & "/" & \$datestrip[2] & "/" & \$datestrip[3]-1

MsgBox (0, "Date Calc", "Old Date: "&\$date &@CRLF&"New Date: "&\$newdate)```

You can refine it. Give it ago, add a if statement, If you hit a wall, come ask for more help . Hope it helps.....

I would use DateAdd() because this aint gonna work always ....

Live for the present,
Dream of the future,
Learn from the past.

##### Share on other sites

I would use DateAdd() because this aint gonna work always ....

```#Include <date.au3>

Dim \$date
\$date = _NowDate()
MsgBox(0,"",\$date)

\$datestrip = StringSplit (\$date, ".")

\$newdate = \$datestrip[1] & "/" & \$datestrip[2] & "/" & \$datestrip[3]

MsgBox (0, "Date Calc", "Old Date: "&\$date &@CRLF&"New Date: "&\$newdate)

;in a line code up \$newdate = \$datestrip[1] & "/" & \$datestrip[2] & "/" & \$datestrip[3]
;\$datestrip[1] if you add a number to this you will add day
;\$datestrip[2] if you add a number to this you will add month
;\$datestrip[3] if you add a number to this you will add year
;all of this goes for any math operation```

##### Share on other sites

I was more thinking of this method:

```#Include<date.au3>
\$InputDate = "070508"
\$CalcDate = "20" & StringMid(\$inputdate,1,2) & "/" & StringMid(\$inputdate,3,2) & "/" & StringMid(\$inputdate,5,2)
ConsoleWrite("Inputdate - 1 is " & \$NewDate & @LF)```

Live for the present,
Dream of the future,
Learn from the past.

thanks so much

## Create an account

Register a new account