Jump to content

First and Last date of the month


Kyraga
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
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)
Link to comment
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.

Link to comment
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!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...