Sign in to follow this  
Followers 0
kiffab

Convert SQL Date Format

6 posts in this topic

Hi

I'm connecting to a database, running a query and pulling a date back.

Example:

SELECT max(createddate) FROM table1

In my AutoIt output I will see something like:

201107282103

I tried using the date convert in the SQL query, which works in Management Studio but not via AutoIt.

Is there any way to convert this via AutoIt?

Thanks

Share this post


Link to post
Share on other sites



Use StringRegExp(), its fun :)

Share this post


Link to post
Share on other sites

What format do you want to convert it to? This website lists a lot of possibilities:

http://www.sql-server-helper.com/tips/date-formats.aspx


#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

What format do you want to convert it to? This website lists a lot of possibilities:

http://www.sql-server-helper.com/tips/date-formats.aspx

I don't believe it.... I was on this exact page earlier trying the conversions and thought they werent working in AutoIt. I must've been doing something wrong as it worked in Management Studio. DOH!

Tried again and bingo, it's working.

Thanks :)

Share this post


Link to post
Share on other sites

I don't believe it.... I was on this exact page earlier trying the conversions and thought they werent working in AutoIt. I must've been doing something wrong as it worked in Management Studio. DOH!

Tried again and bingo, it's working.

Thanks :)

You weren't holding your tongue right. ;)


#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

Local $String = "20110722141500"
Local $DateTime = StringRegExpReplace($String, "(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})", "\1/\2/\3 \4:\5:\6")
ConsoleWrite($String & " to " & $DateTime & @LF)
$DateCalc = _DateDiff( 'n',$DateTime,_NowCalc())
ConsoleWrite($DateCalc & @CRLF)

If converting from SQL is not an option (like excel/outlook for example).

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