Sign in to follow this  
Followers 0
HardCopy

_DateYearFirst UDF

6 posts in this topic

#1 ·  Posted (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

;===============================================================================
;
; 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 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

Share this post


Link to post
Share on other sites



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)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 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

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Nice... 8)

8)


NEWHeader1.png

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