Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Julian to gregorian convertion with sql query

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
Lenzbanu

New User


Joined: 08 Mar 2005
Posts: 2

PostPosted: Wed Jul 08, 2009 10:28 am    Post subject: Julian to gregorian convertion with sql query
Reply with quote

can anyone suggest me how to make Julian to gregorian conversion with sql query and vice versa.
Back to top
View user's profile Send private message

Lenzbanu

New User


Joined: 08 Mar 2005
Posts: 2

PostPosted: Wed Jul 08, 2009 11:00 am    Post subject: Reply to: Julian to gregorian convertion with sql query
Reply with quote

To convert from gregorian to julian date, i tried the following
select date('2009-01-01') as dt,
year('2009-01-01') * 1000 + dayofyear('2009-01-01') as dt1
from temp1;

require suggestion?
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1224
Location: Israel

PostPosted: Wed Jul 08, 2009 3:21 pm    Post subject:
Reply with quote

Don't know about better/other solutions, but that does the work:
Code:
SELECT DATE('2009-07-08') AS DT,                         
YEAR('2009-07-08') * 1000 + DAYOFYEAR('2009-07-08') AS DT1
FROM SYSIBM.SYSDUMMY1


Ketan Varhade wrote:
This save the MIPS
Forget about the MIPS, better save the whales!
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jul 08, 2009 3:27 pm    Post subject:
Reply with quote

a date can be generated by adding the julian DDD - 1 to Jan, 01 of the julian YY.

a julian date can be generated by using the difference in days - 1 between a date and Jan 01 of the year

marso, you posted while I was composing. yours is a better solution,
Back to top
View user's profile Send private message
Ketan Varhade

Active User


Joined: 29 Jun 2009
Posts: 197
Location: Mumbai

PostPosted: Wed Jul 08, 2009 3:27 pm    Post subject:
Reply with quote

Hi Marso,
This query wont be dynamic and needs to be changed every time. If the requirement is to run on the SPUFI,QMF then fine but for runing in the embeded COBOL-DB2 then the above mentioned logic can be right.

Correct me if I am wrong.

Thanks
Ketan Varhade
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jul 08, 2009 3:30 pm    Post subject:
Reply with quote

Ketan Varhade
replace the hardcoded date with a host variable containing a db2 date datatype value.

you have been corrected.
Back to top
View user's profile Send private message
Ketan Varhade

Active User


Joined: 29 Jun 2009
Posts: 197
Location: Mumbai

PostPosted: Wed Jul 08, 2009 3:36 pm    Post subject:
Reply with quote

Thanks
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1224
Location: Israel

PostPosted: Wed Jul 08, 2009 5:15 pm    Post subject: Reply to: Julian to gregorian convertion with sql query
Reply with quote

Lenzbanu provided both question and answer from the beginning.
I did nothing but correct the FROM, run it under QMF and check the result.

Quote:
replace the hardcoded date with a host variable
that should have been obvious to everybody.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jul 08, 2009 5:28 pm    Post subject:
Reply with quote

Quote:
that should have been obvious to everybody


Marso, you forget where you are.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us