Search the Community
Showing results for tags 'Date functions'.
-
Hi all , This is a little function to get a valid date value from given 3 integer values. For example, if we give 2008, 10, 25 as parameters, it will give a valid date from it. Here is the code #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.12.0 Author: kcvinu Build Date : 09-03-2015 Script Function: It will give a valid date as output if you give year month and date. Example DigitsToDate(2011,8,26,1) will give 26/08/2011 Last parameter is flag ; $flag 1 = dd-mm-yyyy ; $flag 2 = mm-dd-yyyy ; $flag 3 = yyyy-dd-mm ; $flag 4 = yyyy-mm-dd Return Value If all parameters are correct then it will give you a date value as per flag This function will return -1 when you give month greater than 12 or month lesser than 1 This function will return -1 when you give day greater than 31 or month lesser than 1 This function will return -1 when you give year greater than 9999 or lesser than 1 This function will return -2 when you give a leap year as year and month as february and day greater than 29 This function will return -3 when you give day greater than 30 and months which not have more than 30 days Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here Func DigitsToDate($Year, $Month, $Day, $flag) Local $31Club[4] = [4, 6, 9, 11] For $i In $31Club If $i = $Month And $Day > 30 Then Return -3 Next Local $LeapFlag If StringRight($Year, 2) = 00 Then If IsFloat($Year / 400) Then $LeapFlag = 0 Else $LeapFlag = 1 EndIf ElseIf StringRight($Year, 2) <> 00 Then If IsFloat(StringRight($Year, 2) / 4) Then $LeapFlag = 0 Else $LeapFlag = 1 EndIf EndIf If $LeapFlag = 1 And $Month = 2 And $Day > 29 Then Return -2 If StringLen($Year) <> 4 Then Return -1 If StringLen($Month) > 2 Then Return -1 If StringLen($Day) > 2 Then Return -1 If $Year < 1 Then Return -1 If $Month < 1 Or $Month > 12 Then Return -1 If $Day < 1 Or $Day > 31 Then Return -1 If $Month < 10 And StringLen($Month) = 1 Then $Month = 0 & $Month If $Day < 10 And StringLen($Day) = 1 Then $Day = 0 & $Day If $flag = 1 Then Return $Day & "/" & $Month & "/" & $Year If $flag = 2 Then Return $Month & "/" & $Day & "/" & $Year If $flag = 3 Then Return $Year & "/" & $Day & "/" & $Month If $flag = 4 Then Return $Year & "/" & $Month & "/" & $Day EndFunc ;==>DigitsToDate And here is the *.au3 file DigitsToDate.au3