× 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.



There are a lot of ways to convert decimal dates to iso dates in SQL. I
used to use a custom SQL function to convert them, since the function call
is short and sweet. However, I had the function coded in such a way that
errors were sent to the job log when encountering an invalid decimal date.

Now, I prefer to use a table that contains a cross reference between the
decimal dates and iso dates, and simply join to the table to fetch the
converted value. This way, no error spam results when you process an
invalid decimal date. To convert from decimal to iso date, join using the
decimal date. To convert from iso date to decimal date, join using the iso
date. Example (decimal to ISO):

select ORDER_DATE.ISO_DATE, SHIP_DATE.ISO_DATE
from ORDER O
left join DATE_XREF ORDER_DATE
on ORDER_DATE.DECIMAL_DATE = O.ORDER_DATE
left join DATE_XREF SHIP_DATE
on SHIP_DATE.DECIMAL_DATE = O.SHIP_DATE and O.SHIP_DATE <> 0

Resulting code is simple, easy to read, and no error spam results in the
job log. Since the code is so simple, I think it is fairly easy to
encourage other developers to use it.

If you go the function route, try to use one that does not error spam your
job log when processing invalid decimal dates.

If you code these conversions inline, if you have multiple developers,
they'll likely use different techniques for date conversions (little
consistency).

If you use a table to perform the conversions, make sure you have an index
present for each type of conversion.

This tip, brought to you, from vacation in Puerto Vallarta, MX! Happy new
year!

Mike

I have a field in a data file which is 7/0 and is cyymmdd. I want to
use
it as a date field so I can get the week. Presently that is being done
by
substringing the digits and replacing the leading "1" with a "20". That
seems cumbersome to me but maybe thats the only way to do it?

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

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.