Jump to content

_DateYearFirst UDF


HardCopy
 Share

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...