Jump to content
Sign in to follow this  
kabjar

Day, Month and Year VB-like functions?

Recommended Posts

kabjar

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

Share this post


Link to post
Share on other sites
Andreik

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

Share this post


Link to post
Share on other sites
kabjar

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

Share this post


Link to post
Share on other sites
Andreik

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

Share this post


Link to post
Share on other sites
kabjar

#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

Share this post


Link to post
Share on other sites
thenewkid

@MON

MsgBox(0,"",@MON)
Edited 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

Share this post


Link to post
Share on other sites
Andreik

@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

Share this post


Link to post
Share on other sites
Andreik

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

Share this post


Link to post
Share on other sites
kabjar

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

Share this post


Link to post
Share on other sites
Andreik

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

Share this post


Link to post
Share on other sites
kabjar

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

Thank you...#kabjar

Share this post


Link to post
Share on other sites
Andreik

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

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  

×