473,387 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

SQL Converting decimal type to date type

Hello,

I'm trying to convert a decimal (9,0) to date from a db2 table

20150105 would be 01/05/2015
20160202 would be 02/02/2015
YYYYMMDD


not sure why its setup as 9 versus 8.

Would these values have a 0 in front since its setup for 9?

The reason is I need to calculate date ranges and I cannot simply add/subtract a number on this value for beginning/end of month values.

for example subtract 2 days from 1/1/2016 would be 12/30/2015
Jan 14 '16 #1
3 3754
Rabbit
12,516 Expert Mod 8TB
Use the DB2 CAST() function to convert the number to a string so you can add in the slashes to the date. Then use CAST() again to convert the newly formatted string to a date.
Jan 14 '16 #2
Hi Rabbit,

I should have clarified I do not need to reformat the data to MM/DD/YYYY but rather convert the decimal data type to a date datatype.

I am trying to add/subtract days to the data like the example below.

SELECT VARCHAR_FORMAT(CURRENT TIMESTAMP + 10 DAYS,
'YYYYMMDD')

So far I have been able to do CAST to convert to string. I'm stuck at convert the string to a date dataype.


CAST(SETTLE_DATE AS CHAR (8))
Jan 15 '16 #3
Rabbit
12,516 Expert Mod 8TB
That's because it doesn't recognize 8 numbers in a row as a valid date format. That's why I said you need to cast it to a string so you can add in the slashes before trying to cast it to a date.
Jan 15 '16 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Marcelo López | last post by:
Hello everybody. I'm working with an office pivot table and i have to convert from its currency type to a decimal (in C#) , operate with the result and then re-convert it to the currency type to...
3
by: usenet | last post by:
I have inherited a table where date information was saved from PHP as a VARCHAR. (Sigh.) This means that the so-called date fields look like this : August 1, 2005, 9:09 am EDT October 13, 2004,...
6
by: Gilgamesh | last post by:
Is decimal type a good choice to use for storing currency? I've got a situation that when I store 8.50 in a decimal type variable and read it back, I'm getting 8.5. Is there a better data type to...
7
by: | last post by:
Source Error: Line 173: sData(rownumber - 1, lcnt) = WhatCol.Value Line 174: End IF Line 175: If (sData(rownumber, lcnt) = sData(rownumber - 1, lcnt)) AND...
1
by: .Net Sports | last post by:
I have an itemdatabound function whereas I am declaring a var named "price" as a decimal, and then want to reassign it to the value of a double datatype "dblTotalVolume", but I get an error "cannot...
5
by: Donkey | last post by:
Hello, I want to find out how many digits does each date type have and how many bytes does it occupy in memory, so I wrote a program below: #include <stdio.h> const long double...
3
by: Sharon | last post by:
There is an built-in types table for .NET framework type to C# type which are aliases of predefined types in the System namespace (http://msdn2.microsoft.com/en-US/library/ya5y69ds.aspx). How...
3
by: Boot2TheHead | last post by:
This one cost me a solid half hour yesterday. I'm wondering why on earth the default precision for a decimal type is 18,0. Maybe I'm mistaken. A decimal datatype sort of implies that you'd want...
8
by: Steve Cartnal | last post by:
I have tried every function that seemed applicable and can't seem to convert a simple text field containing numbers, for example "022807", into a date. Nor can I do the reverse and convert a date...
12
by: Frank Millman | last post by:
Hi all I have a standard requirement for a 'decimal' type, to instantiate and manipulate numeric data that is stored in a database. I came up with a solution long before the introduction of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.