Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 1275
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: 6970
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: 6970
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: 1275
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: 6970
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 Query to compare 2 values of 1 column... Poha Eater DB2 13 Fri Mar 09, 2018 10:45 am
No new posts How to replace the below query? pkmurali DB2 12 Tue Feb 27, 2018 9:51 pm
No new posts Need Guidance regarding UPDATE query Poha Eater DB2 3 Mon Feb 12, 2018 11:35 pm
No new posts Query to skip Max time-stamp and fetc... vickey_dw DB2 8 Sun Jan 28, 2018 1:09 am
No new posts reg query on DYNALLOC feature raghuraman123 SYNCSORT 12 Wed Jan 10, 2018 2:42 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us