Jump to content
Sign in to follow this  
WorknMan

Coverting a date like: Fri, 4 Feb 2011 15:23:19

Recommended Posts

WorknMan

Just wondering if there is a function to convert a date like Fri, 4 Feb 2011 15:23:19 to the following format:

YYYYMMDDHHMMSS

Reason why I'm asking is because I have an array of these dates that I'm pulling from RSS feeds, and I need to sort the array from earliest date to latest.

Or maybe there's another, more elegant way to go about this? :)

Share this post


Link to post
Share on other sites
Xenobiologist

$before = "Fri, 4 Feb 2011 15:23:19"
;$after = "YYYYMMDDHHMMSS"

ConsoleWrite(_convertDate($before) & @CRLF)

Func _convertDate($date)
    Local $year = StringRegExp($date, '\d{4}', 3)
    Local $month = StringRegExp($date, '([a-zA-Z]{3}) \d', 3)
    Local $day = StringRegExp($date, ',\s(\d+)', 3)
    Local $time = StringRegExp($date, '(\d+):(\d+):(\d+)', 3)
    Switch $month[0]
        Case 'Jan'
            $month[0] = '01'
        Case 'Feb'
            $month[0] = '02'
        Case 'Mar'
            $month[0] = '03'
        Case 'Apr'
            $month[0] = '04'
        Case 'May'
            $month[0] = '05'
        Case 'Jun'
            $month[0] = '06'
        Case 'Jul'
            $month[0] = '07'
        Case 'Aug'
            $month[0] = '08'
        Case 'Sep'
            $month[0] = '09'
        Case 'Oct'
            $month[0] = '10'
        Case 'Nov'
            $month[0] = '11'
        Case 'Dec'
            $month[0] = '12'
    EndSwitch
    Return $year[0] & $month[0] & StringFormat('%.2i', $day[0]) & $time[0] & $time[1] & $time[2]
EndFunc   ;==>_convertDate

Edited by Xenobiologist

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
WorknMan

Sweet, that's going to save me some time :) Thanks!

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.