473,761 Members | 10,498 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

decimal to date

I've probably asked this before, but I can't remember the answer!

One can use the DECIMAL function to convert a date to a decimal.
For instance
values decimal(current _date)
returns 20080528.

Is there an easy way to convert the decimal value back to a date?
I can't use DATE(<decimal-value>) because it expects the decimal value to be
the number of days since Jan 1, 0001.

I'm sure I could write a function to do what I need, but I don't want to
waste my time if it already exists.

DB2/LUW 9.5.

Thanks,
Frank
Jun 27 '08 #1
9 4717
Frank Swarbrick wrote:
I've probably asked this before, but I can't remember the answer!

One can use the DECIMAL function to convert a date to a decimal.
For instance
values decimal(current _date)
returns 20080528.

Is there an easy way to convert the decimal value back to a date?
I can't use DATE(<decimal-value>) because it expects the decimal
value to be the number of days since Jan 1, 0001.

I'm sure I could write a function to do what I need, but I don't want
to waste my time if it already exists.

DB2/LUW 9.5.

Thanks,
Frank
This groups archive (in Google) shows a nice solution (amongst others) by
Tonkuma:

DATE(TRANSLATE( 'ABCD-EF-GH',DIGITS(MYDA TE),'ABCDEFGH') )

[where MYDATE is your decimal-date-field].

The thread was called "Convert DECIMAL to DATE" and was started on 20060308
;o)

Cheers!

--
Jeroen
Jun 27 '08 #2
The Boss wrote:
Frank Swarbrick wrote:
>I've probably asked this before, but I can't remember the answer!

One can use the DECIMAL function to convert a date to a decimal.
For instance
values decimal(current _date)
returns 20080528.

Is there an easy way to convert the decimal value back to a date?
I can't use DATE(<decimal-value>) because it expects the decimal
value to be the number of days since Jan 1, 0001.

I'm sure I could write a function to do what I need, but I don't want
to waste my time if it already exists.

DB2/LUW 9.5.

Thanks,
Frank

This groups archive (in Google) shows a nice solution (amongst others) by
Tonkuma:

DATE(TRANSLATE( 'ABCD-EF-GH',DIGITS(MYDA TE),'ABCDEFGH') )
In DB2 9.5 you can also use TIMESTAMP_FORMA T() (aka TO_DATE) after
converting the beast to a string.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jun 27 '08 #3
>>On 5/28/2008 at 7:35 PM, in message
<6a************ *@mid.individua l.net>,
Serge Rielau<sr*****@ ca.ibm.comwrote :
The Boss wrote:
>Frank Swarbrick wrote:
>>I've probably asked this before, but I can't remember the answer!

One can use the DECIMAL function to convert a date to a decimal.
For instance
values decimal(current _date)
returns 20080528.

Is there an easy way to convert the decimal value back to a date?
I can't use DATE(<decimal-value>) because it expects the decimal
value to be the number of days since Jan 1, 0001.

I'm sure I could write a function to do what I need, but I don't want
to waste my time if it already exists.

DB2/LUW 9.5.

Thanks,
Frank

This groups archive (in Google) shows a nice solution (amongst others)
by
>Tonkuma:

DATE(TRANSLATE ('ABCD-EF-GH',DIGITS(MYDA TE),'ABCDEFGH') )
In DB2 9.5 you can also use TIMESTAMP_FORMA T() (aka TO_DATE) after
converting the beast to a string.
Thanks Serge and 'Boss'.
This is what I came up with:

CREATE FUNCTION date_from_decim al (dec_date DECIMAL(8))
RETURNS DATE
SPECIFIC date_from_decim al8
LANGUAGE SQL
CONTAINS SQL
NO EXTERNAL ACTION
DETERMINISTIC
RETURN DATE(TIMESTAMP_ FORMAT(DIGITS(d ec_date),'YYYYM MDD'));

Works like a charm.
Still think that something like it should be built in to DB2, but perhaps
it's not that common...

Frank

Jun 27 '08 #4
>>On 5/29/2008 at 9:46 AM, in message
<48************ ******@efirstba nk.com>,
Frank Swarbrick<Fr*** **********@efir stbank.comwrote :
>>>On 5/28/2008 at 7:35 PM, in message
<6a************ *@mid.individua l.net>,
Serge Rielau<sr*****@ ca.ibm.comwrote :
>The Boss wrote:
>>Frank Swarbrick wrote:
I've probably asked this before, but I can't remember the answer!

One can use the DECIMAL function to convert a date to a decimal.
For instance
values decimal(current _date)
returns 20080528.

Is there an easy way to convert the decimal value back to a date?
I can't use DATE(<decimal-value>) because it expects the decimal
value to be the number of days since Jan 1, 0001.

I'm sure I could write a function to do what I need, but I don't want
to waste my time if it already exists.

DB2/LUW 9.5.

Thanks,
Frank

This groups archive (in Google) shows a nice solution (amongst others)
by
>>Tonkuma:

DATE(TRANSLAT E('ABCD-EF-GH',DIGITS(MYDA TE),'ABCDEFGH') )
In DB2 9.5 you can also use TIMESTAMP_FORMA T() (aka TO_DATE) after
converting the beast to a string.

Thanks Serge and 'Boss'.
This is what I came up with:

CREATE FUNCTION date_from_decim al (dec_date DECIMAL(8))
RETURNS DATE
SPECIFIC date_from_decim al8
LANGUAGE SQL
CONTAINS SQL
NO EXTERNAL ACTION
DETERMINISTIC
RETURN DATE(TIMESTAMP_ FORMAT(DIGITS(d ec_date),'YYYYM MDD'));

Works like a charm.
Still think that something like it should be built in to DB2, but
perhaps
it's not that common...
I do have another sort of related question...

Is there a way to automatically issue a SET PATH statement whenever a user
connects?

I want to place the date_from_decim al function in a particular schema that
is not named after any particular user (CREATE FUNCTION
fb_func.date_fr om_decimal), but I also want to allow any user to invoke it
without needing to use the schema qualifier. I know that I can have each
application issue a SET PATH statement prior to invoking the function (SET
PATH = fb_func, CURRENT PATH), but it would be nice to have DB2 do this
automatically.

Thanks,
Frank

Jun 27 '08 #5
On May 29, 9:14 am, "Frank Swarbrick" <Frank.Swarbr.. .@efirstbank.co m>
wrote:
>On 5/29/2008 at 9:46 AM, in message

<483E7B60.6F0F. 008...@efirstba nk.com>,

Frank Swarbrick<Frank .Swarbr...@efir stbank.comwrote :
>>On 5/28/2008 at 7:35 PM, in message
<6a6fipF34p4j.. .@mid.individua l.net>,
Serge Rielau<srie...@ ca.ibm.comwrote :
The Boss wrote:
Frank Swarbrick wrote:
I've probably asked this before, but I can't remember the answer!
>>One can use the DECIMAL function to convert a date to a decimal.
For instance
values decimal(current _date)
returns 20080528.
>>Is there an easy way to convert the decimal value back to a date?
I can't use DATE(<decimal-value>) because it expects the decimal
value to be the number of days since Jan 1, 0001.
>>I'm sure I could write a function to do what I need, but I don't want
to waste my time if it already exists.
>>DB2/LUW 9.5.
>>Thanks,
Frank
>This groups archive (in Google) shows a nice solution (amongst others)
by
Tonkuma:
>DATE(TRANSLATE ('ABCD-EF-GH',DIGITS(MYDA TE),'ABCDEFGH') )
In DB2 9.5 you can also use TIMESTAMP_FORMA T() (aka TO_DATE) after
converting the beast to a string.
Thanks Serge and 'Boss'.
This is what I came up with:
CREATE FUNCTION date_from_decim al (dec_date DECIMAL(8))
RETURNS DATE
SPECIFIC date_from_decim al8
LANGUAGE SQL
CONTAINS SQL
NO EXTERNAL ACTION
DETERMINISTIC
RETURN DATE(TIMESTAMP_ FORMAT(DIGITS(d ec_date),'YYYYM MDD'));
Works like a charm.
Still think that something like it should be built in to DB2, but
perhaps
it's not that common...

I do have another sort of related question...

Is there a way to automatically issue a SET PATH statement whenever a user
connects?

I want to place the date_from_decim al function in a particular schema that
is not named after any particular user (CREATE FUNCTION
fb_func.date_fr om_decimal), but I also want to allow any user to invoke it
without needing to use the schema qualifier. I know that I can have each
application issue a SET PATH statement prior to invoking the function (SET
PATH = fb_func, CURRENT PATH), but it would be nice to have DB2 do this
automatically.

Thanks,
Frank
If the users are connecting via CLP, I don't know of another way other
than setting it each time. If they're connecting via other means, you
could try setting the current (function) path via the cli.ini. Also--
again depending on how users are connecting--the application server/
ORM layer/JDBC layer may have its own ini file that you could put the
entry (or its equivalent) in.

--Jeff
Jun 27 '08 #6
jefftyzzer wrote:
>I want to place the date_from_decim al function in a particular schema that
is not named after any particular user (CREATE FUNCTION
fb_func.date_f rom_decimal), but I also want to allow any user to invoke it
without needing to use the schema qualifier. I know that I can have each
application issue a SET PATH statement prior to invoking the function (SET
PATH = fb_func, CURRENT PATH), but it would be nice to have DB2 do this
automaticall y.
You want a .login. Yeah it's on my wish list, too.
Keeps popping up, but never (so far) made the cut.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jun 27 '08 #7
>>On 5/29/2008 at 11:15 AM, in message
<41************ *************** *******@i18g200 0prn.googlegrou ps.com>,
jefftyzzer<je** ******@sbcgloba l.netwrote:
On May 29, 9:14 am, "Frank Swarbrick" <Frank.Swarbr.. .@efirstbank.co m>
wrote:
>>
Is there a way to automatically issue a SET PATH statement whenever a
user
>connects?

I want to place the date_from_decim al function in a particular schema
that
>is not named after any particular user (CREATE FUNCTION
fb_func.date_f rom_decimal), but I also want to allow any user to invoke
it
>without needing to use the schema qualifier. I know that I can have
each
>application issue a SET PATH statement prior to invoking the function
(SET
>PATH = fb_func, CURRENT PATH), but it would be nice to have DB2 do this
automaticall y.

If the users are connecting via CLP, I don't know of another way other
than setting it each time. If they're connecting via other means, you
could try setting the current (function) path via the cli.ini. Also--
again depending on how users are connecting--the application server/
ORM layer/JDBC layer may have its own ini file that you could put the
entry (or its equivalent) in.
We'll be connecting either from JDBC (via Websphere) and from host DRDA
client applications.

Thanks for the ideas.

Frank

Jun 27 '08 #8
On May 29, 4:07 pm, "Frank Swarbrick" <Frank.Swarbr.. .@efirstbank.co m>
wrote:
>On 5/29/2008 at 11:15 AM, in message

<4154d8a4-908d-49b7-90f4-ae3d1e500...@i1 8g2000prn.googl egroups.com>,

jefftyzzer<jeff tyz...@sbcgloba l.netwrote:
On May 29, 9:14 am, "Frank Swarbrick" <Frank.Swarbr.. .@efirstbank.co m>
wrote:
Is there a way to automatically issue a SET PATH statement whenever a
user
connects?
I want to place the date_from_decim al function in a particular schema
that
is not named after any particular user (CREATE FUNCTION
fb_func.date_fr om_decimal), but I also want to allow any user to invoke
it
without needing to use the schema qualifier. I know that I can have
each
application issue a SET PATH statement prior to invoking the function
(SET
PATH = fb_func, CURRENT PATH), but it would be nice to have DB2 do this
automatically.
If the users are connecting via CLP, I don't know of another way other
than setting it each time. If they're connecting via other means, you
could try setting the current (function) path via the cli.ini. Also--
again depending on how users are connecting--the application server/
ORM layer/JDBC layer may have its own ini file that you could put the
entry (or its equivalent) in.

We'll be connecting either from JDBC (via Websphere) and from host DRDA
client applications.

Thanks for the ideas.

Frank
Frank,

In re: WebSphere, I just spoke to one of our administrators, who gave
me some information that might be helpful to you: You'll want to set
the currentFunction Path Custom Property within your Data Source, which
is itself within the JDBC Providers link in the Resources area of the
WS Admin Console.

HTH,

--Jeff
Jun 27 '08 #9
>>On 5/30/2008 at 12:57 PM, in message
<09************ *************** *******@a32g200 0prf.googlegrou ps.com>,
jefftyzzer<je** ******@sbcgloba l.netwrote:
In re: WebSphere, I just spoke to one of our administrators, who gave
me some information that might be helpful to you: You'll want to set
the currentFunction Path Custom Property within your Data Source, which
is itself within the JDBC Providers link in the Resources area of the
WS Admin Console.
Thanks.
Frank

Jun 27 '08 #10

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

Similar topics

21
4529
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
6
8256
by: Chris Kennedy | last post by:
I am pulling a decimal value from SQL server and trying to use the format currency and format number function. I am using these values in a large string of HTML to be used in a CDONTS Email. If I use the code fragment below the price variable, which is 3.92 in the database, shows up as £392. When the formatcurrency is removed it is displayed as 3.92 but!!!! if I concatenate a "£" it displays £392. I have read some posts about VBscript not...
4
7833
by: spebola | last post by:
I am using vb.net 2003 professional and I get the following results when using the round method: dim Amount as decimal = 180.255 Amount = Amount.Round(Amount, 2) Amount now contains 180.25. I need it to contain 180.26. Any ideas?
5
43892
by: Ray | last post by:
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('20060308','YYYYMMDD') but I cannot get it to work. What else can I do to conver the data...
0
9521
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
10107
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...
0
9765
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8768
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6599
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
5214
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...
0
5361
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3863
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
3
3442
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.