Sign in to follow this  
Followers 0
kaotkbliss

Date math and fomatting

4 posts in this topic

I display the date (@YEAR&@MON&@MDAY) to get something like 20090904 (exactly as I want the format) yet, if I do any adding or subtracting days it drops leading zeros such as

@YEAR&@MON&@MDAY-1 would yield 2009093

@YEAR&@MON-1&@MDAY would end up 2009903

how can I keep this from happening? I looked through the _date functions but all had different date formats and I could not seem to get them into the YYYYMMDD format I need.


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites



$sDate = Number(@Year & @Mon & @MDay)
$sNew = Number(@Year & StringFormat("%02d", @Mon-1) & StringFormat("%02d",@MDay))


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

You can't directly perform math on dates. What do you get when you subtract from the first day of a month? Zero. What do you get when you add a day to the end of a month? 32.

Use _DateAdd

Share this post


Link to post
Share on other sites

You can't directly perform math on dates. What do you get when you subtract from the first day of a month? Zero. What do you get when you add a day to the end of a month? 32.

Use _DateAdd

I thought that might happen, but I read in another post where someone was doing something similar so I was hoping.

So it would be something like _DateAdd('d',1,YYYYMMDD)?


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
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
Sign in to follow this  
Followers 0