kabjar Posted January 9, 2009 Share Posted January 9, 2009 (edited) Hi to all. Do there in Autoit language exist some functions like Day(), Month() and Year() like in Visual Basic? For example, how can I Msgbox just number of previous month? I know function _DateAdd, but how to MsgBox ONLY month number? Do I have to use some string function (StringMid) to get number of month from result of _DateAdd function? #Include <Date.au3> $sNewDate = _DateAdd( 'm',-1, _NowCalcDate()) MsgBox( 4096, "", "Date one month ago was: " & $sNewDate ) Hope, there is some easier way... Thanks for all comments/suggestions...#kajbar Edited January 9, 2009 by kabjar Link to comment Share on other sites More sharing options...
Andreik Posted January 9, 2009 Share Posted January 9, 2009 Hi to all. Do there in Autoit language exist some functions like Day(), Month() and Year() like in Visual Basic? For example, how can I Msgbox just number of previous month? I know function _DateAdd, but how to MsgBox ONLY month number? Do I have to use some string function (StringMid) to get number of month from result of _DateAdd function? #Include <Date.au3> $sNewDate = _DateAdd( 'm',-1, _NowCalcDate()) MsgBox( 4096, "", "Date one month ago was: " & $sNewDate ) Hope, there is some easier way... Thanks for all comments/suggestions...#kajbarFor me work very fine this: #include <Date.au3> MsgBox( 4096, "", "Date one month ago was: " & _DateAdd("M",-1,_NowCalcDate())) When the words fail... music speaks. Link to comment Share on other sites More sharing options...
kabjar Posted January 9, 2009 Author Share Posted January 9, 2009 For me work very fine this: #include <Date.au3> MsgBox( 4096, "", "Date one month ago was: " & _DateAdd("M",-1,_NowCalcDate())) But I dont want to MsgBox all date, but only number of month (12)! Thanks anyway #kabjar Link to comment Share on other sites More sharing options...
Andreik Posted January 9, 2009 Share Posted January 9, 2009 But I dont want to MsgBox all date, but only number of month (12)! Thanks anyway #kabjar#include <Date.au3> $DATE = _DateAdd("M",-1,_NowCalcDate()) $DATE = StringSplit($DATE,"/") MsgBox(0,"",$DATE[2]) When the words fail... music speaks. Link to comment Share on other sites More sharing options...
kabjar Posted January 9, 2009 Author Share Posted January 9, 2009 #include <Date.au3> $DATE = _DateAdd("M",-1,_NowCalcDate()) $DATE = StringSplit($DATE,"/") MsgBox(0,"",$DATE[2]) Thanx. So there realy doesn exist any easier method (function) to do this?! Never mind, I make some _Month() function myself.... I just wasnt sure.... Regards. #kabjar Link to comment Share on other sites More sharing options...
thenewkid Posted January 9, 2009 Share Posted January 9, 2009 (edited) @MON MsgBox(0,"",@MON) Edited January 9, 2009 by thenewkid some of my scripts check them out and give feedback so i can learn from them :)autoclicker a autoclickernote taker a script to take notes with Link to comment Share on other sites More sharing options...
Andreik Posted January 9, 2009 Share Posted January 9, 2009 @MON MsgBox(0,"",@MON) Func GetPrevMon() If @MON = "01" Then Return "12" Else Return @MON-1 EndIf EndFunc MsgBox(0,"",GetPrevMon()) When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Robjong Posted January 9, 2009 Share Posted January 9, 2009 Take a look at the macros (@MON is the one you need), http://www.autoitscript.com/autoit3/docs/macros.htm Link to comment Share on other sites More sharing options...
kabjar Posted January 9, 2009 Author Share Posted January 9, 2009 Take a look at the macros (@MON is the one you need), http://www.autoitscript.com/autoit3/docs/macros.htmBut macro @MON represents number of current month only, and I need some function, which returns number of month of any date given as parameter - exactly like Month() function in VB....#kabjar Link to comment Share on other sites More sharing options...
Andreik Posted January 9, 2009 Share Posted January 9, 2009 Func GetPrevMon($DATE);YYYY/MM/DD Local $MON = 0 $SPLIT = StringSplit($DATE,"/") If IsArray($SPLIT) Then If $SPLIT[0] >= 3 Then $MON = $SPLIT[2] If $MON = "01" Then $MON = "12" Else $MON = $MON -1 EndIf EndIf EndIf Return $MON EndFunc MsgBox(0,"",GetPrevMon("1798/09/28")) When the words fail... music speaks. Link to comment Share on other sites More sharing options...
kabjar Posted January 9, 2009 Author Share Posted January 9, 2009 Func GetPrevMon($DATE);YYYY/MM/DD Local $MON = 0 $SPLIT = StringSplit($DATE,"/") If IsArray($SPLIT) Then If $SPLIT[0] >= 3 Then $MON = $SPLIT[2] If $MON = "01" Then $MON = "12" Else $MON = $MON -1 EndIf EndIf EndIf Return $MON EndFunc MsgBox(0,"",GetPrevMon("1798/09/28")) This is what I ment....: #include <Date.au3> ;declaration of function for returning number of month of given date Func _Month($Date) $DATE = StringSplit($DATE,"/") Return $DATE[2] EndFunc ;usage of new function MsgBox (0, "", _Month(_DateAdd("M",-1,_NowCalcDate()))) Exit Link to comment Share on other sites More sharing options...
Andreik Posted January 9, 2009 Share Posted January 9, 2009 This is what I ment....: #include <Date.au3> ;declaration of function for returning number of month of given date Func _Month($Date) $DATE = StringSplit($DATE,"/") Return $DATE[2] EndFunc ;usage of new function MsgBox (0, "", _Month(_DateAdd("M",-1,_NowCalcDate()))) ExitIf $Date don't contain "/" your script will give an error. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
kabjar Posted January 9, 2009 Author Share Posted January 9, 2009 I Agree, I can write some better function with checking parameters, but at this moment, its all I need.... Thank you...#kabjar Link to comment Share on other sites More sharing options...
Andreik Posted January 9, 2009 Share Posted January 9, 2009 I Agree, I can write some better function with checking parameters, but at this moment, its all I need.... Thank you...#kabjarYou can check if is a valid date format: #include <Date.au3> Func GetPrevMon($DATE);a valid date format If _DateIsValid($DATE) Then $RESULT = StringRegExp($DATE,"[-/.]\d\d[-/.]",1) Return Number(StringTrimRight(StringTrimLeft($RESULT[0],1),1))-1 EndIf EndFunc MsgBox(0,"",GetPrevMon("1975/09/08")) When the words fail... music speaks. 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