Member Login

Username
Password
Forget Password
New Sign Up
Search Forum

Buy Support
Incidents

If you can't find your answer in the FREE PUBLIC QDeveloper Forum, require URGENT Priority Support, or you need to send us private or confidential information:

Click Here
If you can't login and post questions or you are having trouble viewing forum posts:
Click Here
Callback
Support

If you live in USA, UK, Canada, Australia or New Zealand, you can leave us details on your question and request us to call you back and discuss them with you personally  (charges apply).

Click Here
 
Buy Support
Incidents
If you can't find your answer in the FREE PUBLIC QDeveloper Forum, require URGENT Priority Support, or you need to send us private or confidential information:
Click Here

Forum : Converting date to character in desired formatSearch Forum

Forum Home > QODBC - ODBC Driver for QuickBooks > QODBC SQL Sample Scripts Forum

 New Topic 
 
 Post Reply 
[1]  
 Converting date to character in desired format 
 Author   Message 
  JohnN 
  
 Group: Members 
 Posts: 12 
 Joined: 2006-04-19 
 Profile
 Posted : 2006-04-29 08:01:39

I'm wanting to convert TxnDate in several tables to a character string, with a specified format.

For example, for a date of 2006-04-28, I want the data type to be SQL_CHAR (or SQL_VARCHAR) in the following format:  04/28/2006

Using the CONVERT() function, I'm able to convert the date to either SQL_CHAR or SQL_VARCHAR just fine.  However, if I then try to use LEFT(), SUBSTRING() or RIGHT() on these results (to morph from 2006-04-28 to 04/28/2006), I'm getting BLANK results.  For example, simply:

SELECT TxnDate as TxnDate, {fn LEFT({fn CONVERT(TxnDate, SQL_VARCHAR)},4)} as Temp FROM invoiceline NOSYNC WHERE TxnDate >= ({fn CURDATE()}-60)

Returns NOTHING in the 2nd column?!?!

How can I convert TxnDate into a character string of the format MM/DD/YYYY?

TIA!

 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2006-04-29 10:04:10

Well I'll start with showing everyone how to extract the Month, Day and Year so everyone can take what they want to do with the values from there.

SELECT TxnDate, 
{fn MONTH("TxnDate")} as Month,
{fn DAYOFMONTH("TxnDate")} as Day,
{fn Year("TxnDate")} as Year
FROM invoiceline NOSYNC WHERE TxnDate >= ({fn CURDATE()}-60)

 

  Top 
  JohnN 
  
 Group: Members 
 Posts: 12 
 Joined: 2006-04-19 
 Profile
 Posted : 2006-04-29 13:37:16

As always, thanks for the feedback.

However, I am curious why my approach would not work?  If the CONVERT(..., SQL_VARCHAR) truly returns a varchar, why can't I then manipulate it with the other functions (LEFT(), RIGHT(), etc.)?

Also, using Month() and DayOfMonth() means I have to THEN convert to VARCHAR and manipulate even further. For example, the leading zero issue for Months and Days of Months less than 10 (e.g. I need 04/08/2006, rather than 4/8/2006).

Anyway, just don't understand why I can't simply use string functions after converting to a varchar?!?!?

 

  Top 
 New Topic 
 
 Post Reply 
[1]  

Jump to