DigDeep Posted January 31, 2017 Share Posted January 31, 2017 (edited) I can get the current month name as per below... Local $sLongMonthName = _DateToMonth(@MON) MsgBox(0, '', $sLongMonthName) How can I get Previous Month name ? Edited January 31, 2017 by DigDeep Link to comment Share on other sites More sharing options...
Developers Jos Posted January 31, 2017 Developers Share Posted January 31, 2017 Shouldn't be that hard... something like: #include<date.au3> Local $PrevMonth = @MON-1 if @MON=1 then $PrevMonth = 12 Local $sPrevLongMonthName = _DateToMonth($PrevMonth) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sPrevLongMonthName = ' & $sPrevLongMonthName & @CRLF & '>Error code: ' & @error & @CRLF) Jos DigDeep 1 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 More sharing options...
Gianni Posted January 31, 2017 Share Posted January 31, 2017 also: #include <date.au3> ConsoleWrite("Last month was " & _CalcMonth() & @CRLF) ConsoleWrite("5 Months ago was " & _CalcMonth(-5) & @CRLF) ConsoleWrite("in 21 months will be " & _CalcMonth(21) & @CRLF) ConsoleWrite("8 months before may is " & _CalcMonth(-8, 5) & @CRLF) ; This function Returns the name of the month of $n months ago or in $n months ; default is last month (from now) ; you can optionally pass as first parameter how many months you want to shift ; forward (by a positive integer) or backward (by a negative number) ; and optionally (by a second parameter) also from which month you want start the calculation Func _CalcMonth($_iShift = -1, $_iMonth = @MON) Local $_sStartDate = @YEAR & "/" & StringFormat("%02s", $_iMonth) & "/01" $_iShift *= 1 If _DateIsValid($_sStartDate) Then Local $aDatePart, $aTimePart _DateTimeSplit(_DateAdd("M", $_iShift, $_sStartDate), $aDatePart, $aTimePart) Return _DateToMonth($aDatePart[2], $DMW_LOCALE_LONGNAME) Else Return SetError(-1, 0, 0) EndIf EndFunc ;==>_CalcMonth Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Gianni Posted February 1, 2017 Share Posted February 1, 2017 (edited) Another simpler way to calculate the month number, that doesn't relies on Date.au3 Date.au3 is used for the nice multilingual _DateToMonth() function. #include <date.au3> ConsoleWrite("Last month was " & _DateToMonth(_CalcMonth(-1), $DMW_LOCALE_LONGNAME) & @CRLF) ConsoleWrite("2 Months ago was " & _DateToMonth(_CalcMonth(-2), $DMW_LOCALE_LONGNAME) & @CRLF) ConsoleWrite("in 21 months will be " & _DateToMonth(_CalcMonth(21), $DMW_LOCALE_LONGNAME) & @CRLF) ConsoleWrite("3 months before may is " & _DateToMonth(_CalcMonth(-3, 5), $DMW_LOCALE_LONGNAME) & @CRLF) ; This function returns the number of the month of $n months ago or in $n months ; you pass as first parameter how many months you want to shift: ; forward (with a positive integer) or backward (with a negative integer) ; Optionally (with a second parameter) you can set the starting month for the calculation (default is current month) Func _CalcMonth($_iShift = 0, $_iMonth = @MON) $_iShift = Int($_iShift) $_iMonth = Int($_iMonth) If $_iMonth < 1 Or $_iMonth > 12 Then Return SetError(-1, 0, 0) ; "Error: Wrong starting month" Local $x = Mod($_iShift + $_iMonth - 1, 12) Local $_iTarget = 1 + $x + (12 * ($x < 0)) Return SetError(0, 0, $_iTarget) EndFunc ;==>_CalcMonth Edited February 1, 2017 by Chimp removed the multiply * 1 to parameters because not necessary (just int() is enough) Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now