Jump to content

Day, Month and Year VB-like functions?


 Share

Recommended Posts

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 by kabjar
Link to comment
Share on other sites

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

For 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

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

#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

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

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

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
If $Date don't contain "/" your script will give an error.

When the words fail... music speaks.

Link to comment
Share on other sites

I Agree, I can write some better function with checking parameters, but at this moment, its all I need.... :)

Thank you...#kabjar

You 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

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