473,592 Members | 2,921 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert DECIMAL to DATE

Ray
I have a table with some audit date and time columns. Problem is the
developer who stored the data left them as DECIMAL type instead of DATE
and TIME. Is there a way I can convert the DECIMAL type to DATE or
TIME? The column data is in the date form YYYYMMDD (i.e. 20060308 =
March 8 2006).

I want to get the data into a DATE type. I tried
TO_DATE('200603 08','YYYYMMDD') but I cannot get it to work.

What else can I do to conver the data type?

Thanks,
Ray

Mar 8 '06 #1
5 43823
Ray wrote:
I have a table with some audit date and time columns. Problem is the
developer who stored the data left them as DECIMAL type instead of
DATE and TIME. Is there a way I can convert the DECIMAL type to DATE
or TIME? The column data is in the date form YYYYMMDD (i.e. 20060308 =
March 8 2006).

I want to get the data into a DATE type. I tried
TO_DATE('200603 08','YYYYMMDD') but I cannot get it to work.

What else can I do to conver the data type?

Thanks,
Ray


Urgh, horrible one, but this seems to work (MYDATE is the field
containing the DECIMAL value):

DATE(INSERT(INS ERT(LEFT(CHAR(M YDATE),8),5,0,'-'),8,0,'-'))

There must be a more elegant solution though...
HTH,

Dave.

--

Mar 8 '06 #2
Dave Hughes wrote:
Ray wrote:
I have a table with some audit date and time columns. Problem is the
developer who stored the data left them as DECIMAL type instead of
DATE and TIME. Is there a way I can convert the DECIMAL type to DATE
or TIME? The column data is in the date form YYYYMMDD (i.e.
20060308 = March 8 2006).

I want to get the data into a DATE type. I tried
TO_DATE('200603 08','YYYYMMDD') but I cannot get it to work.

What else can I do to conver the data type?

Thanks,
Ray


Urgh, horrible one, but this seems to work (MYDATE is the field
containing the DECIMAL value):

DATE(INSERT(INS ERT(LEFT(CHAR(M YDATE),8),5,0,'-'),8,0,'-'))

There must be a more elegant solution though...
HTH,

Dave.


Well, I've tried a couple more ways and it does seem that the above is
the simplest way to perform the conversion.

Incidentally, it seems that TO_DATE (aka TIMESTAMP_FORMA T), while
initially appearing to be a really cool function that might be able to
parse all sorts of formats and convert them into TIMESTAMP or DATE
values is in fact the most useless function I've ever come across! When
the documentation states:

Valid format strings are:

'YYYY-MM-DD HH24:MI:SS'

It really means exactly that. In other words, "the *ONLY* valid format
string is". I've tried all sorts of other combinations, but even things
as simple as changing the date-separator, re-ordering the date
components, or removing the time portion from the template fails:

db2 => VALUES TO_DATE('2006/03/08 00:00:00', 'YYYY/MM/DD HH24:MI:SS');
SQL0171N The data type, length or value of argument "2" of routine
"SYSIBM.TO_DATE " is incorrect. SQLSTATE=42815

db2 => VALUES TO_DATE('03-08-2006 00:00:00', 'MM-DD-YYYY HH24:MI:SS');
SQL0171N The data type, length or value of argument "2" of routine
"SYSIBM.TO_DATE " is incorrect. SQLSTATE=42815

db2 => VALUES TO_DATE('2006-03-08', 'YYYY-MM-DD');
SQL0171N The data type, length or value of argument "2" of routine
"SYSIBM.TO_DATE " is incorrect. SQLSTATE=42815

Which kind of begs the question, why even bother having the second
argument if it can only take a single value?! Bizarre...
Dave.

--

Mar 8 '06 #3
How about this?
DATE(TRANSLATE( 'ABCD-EF-GH',DIGITS(MYDA TE),'ABCDEFGH') )
or
DATE(INSERT(INS ERT(DIGITS(MYDA TE),5,0,'-'),8,0,'-'))

(Assuming data type of MYDATE is DEC(8,0))

Mar 9 '06 #4
Tonkuma wrote:
How about this?
DATE(TRANSLATE( 'ABCD-EF-GH',DIGITS(MYDA TE),'ABCDEFGH') )
or
DATE(INSERT(INS ERT(DIGITS(MYDA TE),5,0,'-'),8,0,'-'))
Ooh, very nice! I don't think I've ever used the TRANSLATE function
before... That's certainly a recipe I'll keep in mind for future use :-)
(Assuming data type of MYDATE is DEC(8,0))


Yes ... that's why I added the LEFT(..., 8) call in my one, just to
make sure any decimals got stripped off the end, but that could just as
easily be applied to either of your formulae above.
Thanks,

Dave.

--

Mar 9 '06 #5
Ray
Excellent. Thanks a lot to everyone who posted, this was killing me.

Mar 9 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5526
by: tamrakar | last post by:
Please let me know how I can Load a packed decimal date coming from a file from mainframe be loaded into a Oracle table date column? Any help will be appreciated. Thanks,
4
5364
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and calculate days, months, and years. This is not for a college course. It's for my own personal genealogy website. I'm stumped about the code. I'm working on it but not making much progress. Is there any free code available anywhere? I know it...
1
3096
by: ABC | last post by:
How to convert a date string to datetime value with custom date format? e.g. Date String Date Format Result (DateTime value) "05/07/2004" "MM/dd/yyyy" May 7, 2004 "01062005" "ddMMyyyy" June 1, 2005 "09-07-05" "MM-dd-yy" Sept 7, 2005 Is there any functions to convert?
1
4531
by: Sam | last post by:
How do I convert Julian Date to Calendar Date in ASP.Net 1.1 based on following guideline found at Internet? To convert Julian date to Gregorian date: double JD = 2299160.5; double Z = Math.Floor(JD+0.5); double W = Math.Floor((Z - 1867216.25)/36524.25); double X = Math.Floor(W/4);
13
9217
by: Jason | last post by:
Could someone here show me how I would write a vb program to convert decimal ip address to binary? For example a small form with a convert button and a label for the result and a textbox for the ip. So I would want 11000000 10101000 00000010 00001010 tp show up inthe label if I entered 192.168.2.10 into the text box. I have no idea even how to begin this, any help would be great.
13
5582
by: muss | last post by:
how to convert decimal number in a hexadecimal number using C? Please help me. Thanks.
2
2851
nirmalsingh
by: nirmalsingh | last post by:
Hai all, i want to convert decimal to time. for example if i have decimal number 09.6 then i need it as 10.00 and also decimal 10.118 as 11.58. How to convert this? Thanx in advance with Cheers Nirmal.
1
2960
by: Vitaliy | last post by:
Hi I got this wired exception periodically (Python 2.5, Django based application) what does it mean ?
1
9761
by: smdmca | last post by:
I have Julian date, I want to convert it into date. Is there any function in MySql to convert Julian date to date eg- Julian Date- 2455116 Date - Oct - 12, 2009
4
9737
by: Rolandas | last post by:
Hi, Can anyone help me? I need a code in VBA which would convert decimal numbers to the other system bases on number 36. e.g. in this page http://www.translatorscafe.com/cafe/units-converter/numbers/calculator/octal-to-decimal/ decimal to base-36. Can anyone help me with that?
0
7935
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8236
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
5735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5400
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3851
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2379
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1467
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1202
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.