If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > How to convert current_date to julian(105047)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-16-05, 04:22
sun786 sun786 is offline
Registered User
 
Join Date: Feb 2005
Posts: 5
How to convert current_date to julian(105047)

I need a simple query that would return a julian date for the current_date.
For eg. if the current_date is '2005-02-16' the output should be 105047.

Thanks.
Reg
sun
Reply With Quote
  #2 (permalink)  
Old 02-16-05, 07:09
platho platho is offline
Registered User
 
Join Date: Dec 2002
Posts: 58
Is this what you're looking for ?

select julian_day(current timestamp) from sysibm.sysdummy1 ??
Reply With Quote
  #3 (permalink)  
Old 02-16-05, 07:56
sun786 sun786 is offline
Registered User
 
Join Date: Feb 2005
Posts: 5
No bcos that would julian_day( current_date) would return a 7 digit number....
I need the output to be in the format 105047 ( where 1 is century, 05 is year and 047 is day of the year( jan 31+ feb 16 days)).
Please execute the query on DB2 and then let me know.
I have tried with the following query
SELECT CONCAT(CONCAT ('1',SUBSTR(CHAR(YEAR(CURRENT_DATE)),3,2)),SUBSTR( CHAR(DIGITS(DAYOFYEAR(CURRENT_DATE))),8,3)) FROM SYSIBM.SYSDUMMY1;

This would return 107653 but is not working when I substitue in the
user defined sql query in ODBC stage after where clause

like select * from table xyz where somedb2_date = the above query.

HELP.
Reply With Quote
  #4 (permalink)  
Old 02-16-05, 09:14
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
I don't understand why "century" would be "1" for the year 2005 ...
Anyhow, what about the following:

SELECT 1 * 100000 + (YEAR(CURRENT_DATE)-2000) * 1000 + DAYOFYEAR(CURRENT_DATE) FROM SYSIBM.SYSDUMMY1;
Reply With Quote
  #5 (permalink)  
Old 02-16-05, 10:36
sun786 sun786 is offline
Registered User
 
Join Date: Feb 2005
Posts: 5
I will try to view data and let you know if this works.
Reply With Quote
  #6 (permalink)  
Old 02-17-05, 07:10
sun786 sun786 is offline
Registered User
 
Join Date: Feb 2005
Posts: 5
I tried by putting the same query in the where cluase and tried to view data.
I got a error regarding '1' that in the starting of the query.
error : Illegal symbol 1.

SELECT 1 * 100000 + (YEAR(CURRENT_DATE)-2000) * 1000 + DAYOFYEAR(CURRENT_DATE) FROM SYSIBM.SYSDUMMY1
Reply With Quote
  #7 (permalink)  
Old 02-17-05, 07:11
sun786 sun786 is offline
Registered User
 
Join Date: Feb 2005
Posts: 5
I tried by putting the same query in the where cluase and tried to view data.
I got a error regarding '1' that in the starting of the query.
error : Illegal symbol 1.

SELECT 1 * 100000 + (YEAR(CURRENT_DATE)-2000) * 1000 + DAYOFYEAR(CURRENT_DATE) FROM SYSIBM.SYSDUMMY1

the left hand side of my query is a Numeric field.
Reply With Quote
  #8 (permalink)  
Old 02-17-05, 21:23
jacampbell jacampbell is offline
Registered User
 
Join Date: Jan 2005
Posts: 191
Most people, me included, find it VERY difficult to solve syntax problems when they don't know the syntax that created the problem. You must be one of the rare people who can - because you expect the rest of us to be able to.

James Campbell
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On