Sign in to follow this  
Followers 0
bartekd

Array Format for date and time

9 posts in this topic

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

Share this post


Link to post
Share on other sites



What is Query Analyzer? It's most likely formatting the dates for you. AutoIt is likely just leaving them in the SQL internal format.

Share this post


Link to post
Share on other sites

Its part of the SQL Server 2000 install. Is there a way to format this field in an array like the above?

Share this post


Link to post
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)

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Something like that exists? ... :idea:

:party:

I'm not skilled in RegExp so I can't write such wonderfull RegExp things :-(

Me either!! :)

8)


NEWHeader1.png

Share this post


Link to post
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. :)

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