HardCopy Posted December 2, 2005 Share Posted December 2, 2005 (edited) A UDF I created for converting external shortformat dates to the Autoit Way of handling dates, mainly being all Autoit Date UDF's like the date in YYYY/MM/DD & is good discipline for sorting dates to. Most data I process is of the DD/MM/YYYY variety & had to be swapped to year first, so this is what i now use. The UDF name could be more descriptive, suggestions welcome. Feel free to modify & use as you wish. Please note this does not validate the user date, use the official Autoit UDF _DateIsValid on the value returned. Hope someone finds it useful. Edit: Now work with USA date format - Thx Valuator Update: European = 0(Default), USA = 1 HardCopy expandcollapse popup;=============================================================================== ; ; Function Name: _DateYearFirst() ; Description: ; Swaps a short date format of DD/MM/YYYY or MM-DD-YYYY etc to a YYYY-MM-DD ; ; to comply with Autoit way of processing dates, Year First. Handles US & European date format. ; ; *** N:B Does NOT check if the date is Valid. *** ; Parameter(s): $s_Temp = Short format Date, as a String ; $pFrmt = Define if passed date is in European = 0(Default) or USA = 1 Format. ; ; Requirement(s): None ; Return Value(s): On Success - Returns the Short format date, formatted with the four digit Year First. ; On Failure - Returns 0 and sets @ERROR = 1 ; Author(s): HardCopy(LE) v 1.2 Dec 2005 ; ;=============================================================================== ; ;Example $UsrDate = "01.09.2005" $NewDate = _DateYearFirst($UsrDate,0); 0 = (Default)European Format DMY, 1 = USA Format MDY ConsoleWrite($NewDate & @LF) Func _DateYearFirst($sTemp,$pFrmt = 0) Local $sDate Local $vSplit_Chr = StringMid($sTemp,3,1); Identify which char is used to seperate day mth & year If $vSplit_Chr = "/" or $vSplit_Chr = "-" or $vSplit_Chr = "."Then ;;ok Else SetError(1) Return 0 EndIf Local $dArray = StringSplit($sTemp,$vSplit_Chr) If not @error Then If $pFrmt = 0 Then $sDate = $dArray[3] & $vSplit_Chr & $dArray[2] & $vSplit_Chr & $dArray[1] Else $sDate = $dArray[3] & $vSplit_Chr & $dArray[1] & $vSplit_Chr & $dArray[2] EndIf Return $sDate Else SetError(1) Return 0 EndIf EndFunc; <=== _DateYearFirst() Edited December 2, 2005 by HardCopy Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad Link to comment Share on other sites More sharing options...
Valuater Posted December 2, 2005 Share Posted December 2, 2005 We here in the USA use September 1, 2005 or 09/01/2005 maybe you could ad a second feature for the actual output Func _DateYearFirst($sTemp, $tTemp) in any order of the second $NewDate = _DateYearFirst($UsrDate, D-M-Y) $NewDate = _DateYearFirst($UsrDate, M-D-Y) etc 8) Link to comment Share on other sites More sharing options...
HardCopy Posted December 2, 2005 Author Share Posted December 2, 2005 (edited) Sorry Valuator, I just pulled the plug and removed the udf for now, I use solely European date formats and realised after posting here, the US output is incorrect. Back to Finish it properly Apologies HardCopy Edited December 2, 2005 by HardCopy Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad Link to comment Share on other sites More sharing options...
Valuater Posted December 2, 2005 Share Posted December 2, 2005 (edited) no appologies needed for sure... how about reading users input style and outputing users requested style $NewDate = _DateYearFirst($UsrDate, Y-M-D, D-M-Y ) just ideas 8) Edited December 2, 2005 by Valuater Link to comment Share on other sites More sharing options...
HardCopy Posted December 2, 2005 Author Share Posted December 2, 2005 Updated Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad Link to comment Share on other sites More sharing options...
Valuater Posted December 2, 2005 Share Posted December 2, 2005 Nice... 8) 8) 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