DBQuery output format

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
TheEek
Junior Coder
Posts: 31
Joined: Mon Jun 22, 2009 2:53 pm

DBQuery output format

Post by TheEek » Fri Jan 18, 2013 1:53 pm

When I create a script to retrieve date data from a MySQL database, the dates are formatted to (I suppose) local settings. How can I get Macro Scheduler to return them as entered in the database.

example: A table with a value and date time.

Code: Select all

+-------+-------------------------+
| value  | timelog                     |
+-------+-------------------------+
| a        | 2013-01-18 14:42:30 |
+-------+-------------------------+

The Macro Scheduler code to retrieve the data:

Code: Select all

let>str=Driver={MySQL ODBC 5.1 Driver};Server=[server_ip];Database=[database];Uid=[user_id];Pwd=[password];
DBConnect>str,DB1
let>cmd=Select * from example where value ='a';
DBQuery>DB1,%cmd%,av,nr,mf;
mdl>%av_1_1%:%av_1_2%
The select statement on a MySQL console will return the above, but Macro Scheduler will return: "a:18/01/2013 14:42:30"

Which is wrong, I want "a:2013-01-18 14:42:30"
Hopefully there is a simple setting somewhere that doesn't require modification to the host OS. The only other way I can see this being done is by separating the output and putting it back together in a different order.

User avatar
Meryl
Staff
Posts: 124
Joined: Wed Sep 19, 2012 1:53 pm
Location: Texas
Contact:

Post by Meryl » Fri Jan 18, 2013 11:13 pm

Did you check the date/time commands in the help?

TheEek
Junior Coder
Posts: 31
Joined: Mon Jun 22, 2009 2:53 pm

Post by TheEek » Mon Jan 21, 2013 7:50 am

I did, but nothing immediately springs out to me. Considering this is data retrieved from a database, and not using local time, can you give me a hint to which command I should look at please?

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Mon Jan 21, 2013 3:00 pm

Have you tried formatting the date by using the MySQL
DATE_FORMAT(date,format)
command in the Select? Maybe that will override the default.

TheEek
Junior Coder
Posts: 31
Joined: Mon Jun 22, 2009 2:53 pm

Post by TheEek » Wed Jan 23, 2013 7:34 am

Thanks, I'll have a play with that. The only other way around this I can think of is to use a number midstr commands.

I really hate the way we are forced in to doing things with localisation. I can't think of any other reason why this would be so.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Jan 23, 2013 9:12 am

Just as a point of clarification: the format your date is being returned in is nothing to do with Macro Scheduler. Macro Scheduler performs ZERO analysis or parsing of information sent to or retrieved from the database. ALL it does is forward the query onto the database driver specified in the connection string and return the raw data that it returns. It is simply using Microsoft ADO and simply passing raw data back and forth.

So the date format must be down to the driver.

Now, when working with date types in SQL it is quite common to want to use the database date format function. This allows you to specify exactly what format you want returned (and what format you are sending). If you do not use it when inserting your dates could end up wrong in the database.

This is normal whether you're using VBScript,VB,C++ or Macro Scheduler.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

TheEek
Junior Coder
Posts: 31
Joined: Mon Jun 22, 2009 2:53 pm

Post by TheEek » Fri Jan 25, 2013 1:37 pm

Thanks Marcus. I assumed this was a system (or similar) setting, but was hoping for further options in macro scheduler. I'd update the drivers, but I have little hope this will solve this small problem.

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Jan 25, 2013 2:43 pm

So using date_format didn't fix it?

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts