Kyraga Posted September 19, 2010 Posted September 19, 2010 Hello everyone! I was wondering if you can help me out with the difficulty I have encountered. I want my script to generate First date and Last date of the month (in dd/mm/yy format), so then I can paste these dates anywhere I want. (Example - 01.09.10 and 30.09.10) Any help will be appreciated.
JohnOne Posted September 19, 2010 Posted September 19, 2010 (edited) Look at the _Date functions in the helpfile. ie. from the helpfile #include <Date.au3> $iDays = _DateDaysInMonth( @YEAR,@MON ) MsgBox( 4096, "Days in Month", "This month has " & String( $iDays ) & " days in it." ) Edited September 19, 2010 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
seandisanti Posted September 19, 2010 Posted September 19, 2010 (edited) Hello everyone! I was wondering if you can help me out with the difficulty I have encountered. I want my script to generate First date and Last date of the month (in dd/mm/yy format), so then I can paste these dates anywhere I want. (Example - 01.09.10 and 30.09.10) Any help will be appreciated. perhaps.... #include<date.au3> For $x = 1 to 11 $first = "01/" & StringRight("0" & $x,2) & "/10" $last = StringSplit(_DateAdd("d",-1,"2010/" & StringRight("0" & $x+1,2) & "/01"),"/") $last = $last[3] & "/" & StringRight("0" & $x,2) & "/10" MsgBox(0,"Output","First : " & $first & @CRLF & "Last : " & $last) Next $first = "01/12/10" $last = "31/12/10" MsgBox(0,"Output","First : " & $first & @CRLF & "Last : " & $last) yes i cheated on december ***edit*** and added an extra [/autoit] Edited September 19, 2010 by cameronsdad
Malkey Posted September 19, 2010 Posted September 19, 2010 First day of month + 1 month - 1 day = last day of month. #include <Date.au3> Local $sNewDate, $firstDate, $LastDay Local $Year = 2010 Local $Month = 9 $sNewDate = _DateAdd('M', 1, $Year & "/" & $Month & "/" & "01") $sNewDate = _DateAdd('D', -1, $sNewDate) $firstDate = "01." & $Month & "." & $Year $LastDay = StringRegExpReplace($sNewDate, "(\d{4})(?:/)(\d{2})(?:/)(\d{2})", "\3.\2.\1") MsgBox(4096, "Example", $firstDate & " and " & $LastDay)
JohnOne Posted September 20, 2010 Posted September 20, 2010 #include <Date.au3> $iDays = _DateDaysInMonth( @YEAR,@MON ) MsgBox( 4096, "Return", "01/" & String( @MON) & "/" & String(@YEAR)) MsgBox( 4096, "Return", String($iDays) & "/" & String( @MON) & "/" & String(@YEAR)) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Kyraga Posted September 27, 2010 Author Posted September 27, 2010 JohnOne, cameronsdad, Malkey, thank you for your replies! I used JohnOne's solution 'cause it's the simpliest one (from my point of view). Still for @YEAR i had to use StringRight function 'cause String function gave me 20 instead of 2010 (or just 10). So, the final code that i used is this one: #include <Date.au3> $iDays = _DateDaysInMonth( @YEAR,@MON ) MsgBox( 4096, "Return", "01/" & String( @MON) & "/" & StringRight(@YEAR, 2)) MsgBox( 4096, "Return", String($iDays) & "/" & String( @MON) & "/" & StringRight(@YEAR, 2)) Again, thank you for your help!
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