Jump to content

Array Format for date and time


Recommended Posts

I am using ChrisL's _sql.au3 function. I have one issue with the Array and listView. When I run a particular query, it always removes all the spaces, colons, and dashes. Is there a way that it could be formatted better?

Just so you know what I am talking about, here is an example of the same query I ran using Autoit and Query Analyzer.

Results in Array

[0]|1st Dial

[1]|20090415153030

Results in Query Analyzer

1st Dial

------------------------------------------------------

2009-04-15 15:30:30.000

Thanks in Advance

Link to comment
Share on other sites

;Convert YYYYMMDDHHMMSS to YYYY-MM-DD HH:MM:SS
$original = "20090415153030"
$new = StringRegExpReplace($original, "\A(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(?:.*)","$1-$2-$3 $4:$5:$6")
ConsoleWrite($new)

Link to comment
Share on other sites

version without RegExp:

$in = '20090415153030'
$out = DateFormat($in)
MsgBox(0,'Test',$in & ' --> ' & $out)

; yyyymmddhhmmss --> yyyy-mm-dd hh:mm:ss.sss
Func DateFormat($date)
 If $date = '' Then Return ''
 Return StringLeft($date,4) & '-' & StringMid($date,5,2) & '-' & StringMid($date,7,2) & ' ' & _
        StringMid($date,9,2) & ':' & StringMid($date,11,2) & ':' & StringMid($date,13,2) & '.000'
EndFunc
Link to comment
Share on other sites

  • Moderators

version without RegExp:

Something like that exists? ... :)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

;Convert YYYYMMDDHHMMSS to YYYY-MM-DD HH:MM:SS
$original = "20090415153030"
$new = StringRegExpReplace($original, "\A(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(?:.*)","$1-$2-$3 $4:$5:$6")
ConsoleWrite($new)

Thanks allot, this works beautifully. :)

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