× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



tony.richardson@xxxxxxxxxxxx wrote:
I need to run an SQL BETWEEN to compare some date fields.
> The problem Iâm having is our dates are stored in separate
> fields (century, year, month, and day). I've tried to concatenate
> the fields together, but that doesn't seem to work.

Anyone out there done this before?

This an working example of creating a DATE type column for display and selection from a numeric column, the only difference is you wouldn't
have to sub string since you say your columns are already separate.


Select Cust_Id, Inv_Id,
-- Create Invoice Date as ISO date: YYYY-MM-DD
cast(SubStr( Char( Inv_Date ), 1, 4 ) || '-' ||
     SubStr( Char( Inv_Date ), 5, 2 ) || '-' ||
     SubStr( Char( Inv_date ), 7, 2 ) as Date ) as InvDate,

-- Create Invoice Due Date as ISO date: YYYY-MM-DD
cast( SubStr( Char( Inv_Due_Date ), 1, 4 ) || '-' ||
      SubStr( Char( Inv_Due_date ), 5, 2 ) || '-' ||
      SubStr( Char( Inv_Due_Date ), 7, 2 ) as Date ) as InvDueDate,

-- Get invoice age in days
Days( current date ) - Days(
 Cast( SubStr( Char( Inv_Due_Date ), 1, 4 ) || '-' ||
       SubStr( Char( Inv_Due_Date ), 5, 2 ) || '-' ||
       SubStr( Char( Inv_Due_Date ), 7, 2 ) as Date ) ) as InvAge,

( Inv_Amt-Inv_Pay_Amt) as InvTotal from Ar_Trans
Where ( Inv_Amt-Inv_Pay_Amt ) > 0
 and  Days( current date ) - Days(
 Cast( SubStr( Char( Inv_Due_Date ), 1, 4 ) || '-' ||
       SubStr( Char( Inv_Due_Date ), 5, 2 ) || '-' ||
       SubStr( Char( Inv_Due_date ), 7, 2 ) as Date ) ) >= 30
Order By Cust_Id, Inv_Id, InvDueDate;

HTH,
Billy


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.