Sign in to follow this  
Followers 0
Hyflex

Date Minus one issue...

8 posts in this topic

Hey AutoIt,

I have a problem with a date variable.

$ReportDate = @MDAY - 1 & "/" & @MON & "/" & StringRight(@YEAR, 2)

Today's Date minus 1 (to make it yesterdays date) brings up an issue at the end of the month where it doesnt change month correctly and doesn't go back correct.

Please help

- Hyflex

Share this post


Link to post
Share on other sites



Use _DateAdd with a negative number to subtract from the date you input, doing it the way you're doing it will only subtract from the day and the month isn't affected.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Try

_DateToDayValue to get numerical value for the day

subtract 1 to get num value for the day before

then

_DayValueToDate to get gregorian date for that day.

Or perhaps _DateAdd with a negative difference.

William

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I've been looking at _DateAdd using

_DateAdd('d', 1, _NowCalcDate())
but have an issue with the fact the date is in an American format.

I can't work out how to create a pattern using StringRegExpReplace

I really don't want to use the folllowing:

$RawDate = _DateAdd('d', -1, _NowCalcDate())
$DateSmallYear = StringRight(StringLeft($RawDate, 4), 2)
$DateDay = StringRight(StringRight($RawtDate, 5), 2)
$DateMonth = StringLeft(StringRight($RawDate, 5), 2)
$FullDate = $DateDay & "/" & $DateMonth & "/" & $DateSmallYear
Edited by Hyflex

Share this post


Link to post
Share on other sites

If your date format is in mm/dd/yyyy instead of yyyy/mm/dd use the following code to convert it. There are separate formulae depending upon the format of single digit month and day.

$Date = "07/17/2012" ; date in mm/dd/yyyy format
$ConvertedDate = StringRight($Date, 4) & "/" & StringLeft($Date, 2) & "/" & StringMid($Date, 4, 2) ; date in yyyy/mm/dd format
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ConvertedDate = ' & $ConvertedDate & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
; if month or day is single digit and doesn't have leading 0 consistently use the following formula
$Date = "7/7/2012" ; date in mm/dd/yyyy format no leading zeros
$ConvertedDate = StringRight($Date, 4) & "/" & StringFormat("%02s", StringReplace(StringLeft($Date, 2), "/", "")) & "/" & StringFormat("%02s", StringReplace(StringMid($Date, 3, 2), "/", "")) ; date in yyyy/mm/dd format
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ConvertedDate = ' & $ConvertedDate & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

czardas,

Thank you very much for your help that helps me a lot.

BrewManNH,

Wow, thanks for that it again that helped me quite a lot, I'm British we put our dates in the format of: DD/MM/YYYY or (DD/MM/YY)thank you ever so much though.

Cheers guys, you've helped fix something what has been bugging me for months and months.

Share this post


Link to post
Share on other sites

Glad to help. I know exactly what you mean about date confusion with short year format. Good luck with your project. :)

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