kcvinu Posted March 9, 2015 Share Posted March 9, 2015 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 expandcollapse popup#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 Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only) Link to comment Share on other sites More sharing options...
zalomalo Posted March 10, 2015 Share Posted March 10, 2015 Do you bid i could be able to do it in 5 lines ? kcvinu 1 My english shucks, i know it. Link to comment Share on other sites More sharing options...
kcvinu Posted March 10, 2015 Author Share Posted March 10, 2015 I know it is bloated in some ways. And may be you can shrink this. no doubt. Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now