Jump to content

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

Link to comment
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, :D If you hit a wall, come ask for more help :D. Hope it helps.....

Link to comment
Share on other sites

  • Developers

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, :D If you hit a wall, come ask for more help :D. Hope it helps.....

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
Link to comment
Share on other sites

  • Developers

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)
$NewDate = _DateAdd("d",-1,$CalcDate)
ConsoleWrite("Inputdate - 1 is " & $NewDate & @LF)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...