Sign in to follow this  
Followers 0
Valik

2 New Date functions

3 posts in this topic

#1 ·  Posted (edited)

Attached are 2 new date functions I needed. The first, _DateLookupMonth() is essentially a helper function for the other function, however, it has merit on its own. It looks up either the numeric index, full name or 3 character name of a month. It accepts the same 3 formats as input.

The second function, _DateConvert(), is far more useful. It takes 2 formatting strings and a date. The function is supposed to convert from the source format to the destination format based on the specified date. The simple tests I did showed that they worked. I expect bugs in the code, however, as I wrote it hurriedly and tested it only enough to ensure it would work for what I need at the moment. Report any problems here.

Here is a quick sample of using _DateConvert(). This code requires Beta.

#include <ValikDateFunctions.au3>

Local $sDate1 = "11012005"
Local $sDate2 = "12-01-5678"
Local $sResult1 = _DateConvert("mdy", "y/m/d", $sDate1)
MsgBox(4096, "Result1", $sResult1)
Local $sResult2 = _DateConvert("d?m?y", "y/m/d", $sDate2)
MsgBox(4096, "Result2", $sResult2)

Edit: New version attached. This version tries to be a little smarter about what it extracts. It's still necessary to specify ? in place of most unwanted characters, however, the code automatically attempts to extract a logical amount of characters for the source format type. I also updated the example in the post.

Edited by Valik

Share this post


Link to post
Share on other sites



I uploaded a new version which alteres the behavior of _DateConvert(). Source formatting strings are now easier to write and have some built-in intelligence about them.

Share this post


Link to post
Share on other sites

Here's another that's kind of silyy, but it was something I needed.

Func _DateToSeason($iMon = 0, $iDay = 0)
    If $iMon = 0 Then $iMon = @MON;Current month.  Range is 01 to 12
    If $iDay = 0 Then $iDay = @MDAY;Current day of month.  Range is 01 to 31
    
    
    Select
        Case $iMon = 12 Or $iMon <= 2
            If $iMon = 12 Then
                If $iDay <= 21 Then Return 'Autumn'
            EndIf
            
            Return 'Winter'
            
        Case $iMon >= 3 And $iMon <= 5
            If $iMon = 3 Then
                If $iDay <= 20 Then Return 'Winter'
            EndIf
            
            Return 'Spring'
            
        Case $iMon >= 6 And $iMon <= 8
            If $iMon = 6 Then
                If $iDay <= 21 Then Return 'Spring'
            EndIf
            
            Return 'Summer'
            
        Case $iMon >= 9 And $iMon <= 11
            If $iMon = 9 Then
                If $iDay <= 21 Then Return 'Summer'
            EndIf
            
            Return 'Autumn'
            
        Case Else
            Return False
            
    EndSelect
EndFunc  ;==>_DateToSeason

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