Sign in to follow this  
Followers 0
Kyraga

First and Last date of the month

6 posts in this topic

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.

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by cameronsdad

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

#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.

Share this post


Link to post
Share on other sites

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!

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