Jump to content

Array Dates from CSV as numbers. Trying to convert.


Recommended Posts

By re-arranging the back-references order in the "replace" parameter of the StringRegExpReplace function,  the date format can be manipulated as desired.

Local $iDate = 20130818000000

Local $sDate = StringRegExpReplace(String($iDate), "(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})", "\1/\2/\3 \4:\5:\6") ; format "yyy/MM/dd HH:mm:ss"
ConsoleWrite($sDate & @LF)

$sDate1 = StringRegExpReplace(String($iDate), "(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})", "\3/\2/\1 \4:\5:\6") ; format "MM/dd/yyy HH:mm:ss"
ConsoleWrite($sDate1 & @LF)
Link to comment
Share on other sites

Thanks for the reply Malkey.

So do I need to loop through every instance in my column in the array to do this?

Yes, a loop is needed to access the data stored in an array.

An example:-

;#include <Array.au3>

Local $sDate
Local $aCsvArr[4][3] = [[20130818143000, 1, 2],[20130819000000, 3, 4],[20130820000000, 5, 6],[20130821000000, 7, 8]]
;_ArrayDisplay($aCsvArr)

For $i = 0 To UBound($aCsvArr) - 1
    $sDate = StringRegExpReplace(String($aCsvArr[$i][0]), "(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})", "\1/\2/\3 \4:\5:\6") ; format "yyy/MM/dd HH:mm:ss"
    ;$sDate = StringRegExpReplace(String($aCsvArr[$i][0]), "(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})", "\3/\2/\1 \4:\5:\6") ; format "MM/dd/yyy HH:mm:ss"
    ConsoleWrite($sDate & @LF)
Next
Link to comment
Share on other sites

dar100111,

Look at this notation

$aCsvArr[$i][0]

That means reference whatever is at row $i and column 1.  $i iterates from 0 to the limit of the array.

If you want to reference the data at column 2 of each row then it would look like

$aCsvArr[$i][1]

* - arrays are 0 offset

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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...