IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Arithmetic and Comparisions on dates


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Naga Rajender.K

New User


Joined: 19 Dec 2008
Posts: 13
Location: Hyderabad

PostPosted: Mon May 04, 2009 6:06 pm
Reply with quote

Hi,

I want to perfrom arithmetic operations on two dates and agin i need to get a date in result.

Code:
05 WS-DATE-1.
              10 WS-DD-1          PIC X(02).
              10 FILLER              PIC X(01) VALUE "/".
              10 WS-MM-1          PIC X(02).
              10 FILLER              PIC X(01) VALUE "/".
              10 WS-YYYY-1        PIC X(04).

05 WS-DATE-2.
              10 WS-DD-2          PIC X(02).
              10 FILLER              PIC X(01) VALUE "/".
              10 WS-MM-2          PIC X(02).
              10 FILLER              PIC X(01) VALUE "/".
              10 WS-YYYY-2        PIC X(04).


i want to:

COMPUTE WS-DATE = WS-DATE-1 - WS-DATE-2

(I this this won't work.For this will i use intrinsic functions?i.e do i need to required format to use in intrinsic functions)

IF WS-DATE-1 > WS-DATE-2
do some thing
ELSE
do something
END-IF

(Is this ok. Can i do this without formating)

Please help me out.

Thanks in advance
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon May 04, 2009 6:18 pm
Reply with quote

As specified, 31/01/2000 would compare larger than 01/05/2009. As long as this is what you want, your IF statement is fine.

You'll need to use INTEGER-OF-DATE to convert dates into integers before adding and subtracting -- or you can go through the elaborate process of handling days, months, years separately. You will need to convert your date with slashes into YYYYMMDD format before invoking the function.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Mon May 04, 2009 6:25 pm
Reply with quote

Quote:
(I this this won't work.For this will i use intrinsic functions?i.e do i need to required format to use in intrinsic functions)
For instance:
argument-1
Must be an integer of the form YYYYMMDD
Quote:
(Is this ok. Can i do this without formating)
Not with the format DD/MM/YYYY, but you could if the format was YYYY/MM/DD.
Back to top
View user's profile Send private message
Naga Rajender.K

New User


Joined: 19 Dec 2008
Posts: 13
Location: Hyderabad

PostPosted: Mon May 04, 2009 6:43 pm
Reply with quote

Thank you for quick reply. Is there any values clause for date arithmetic in DB2.

I got SELECT on SYSIBM.SYSDUMMY1 table.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon May 04, 2009 11:45 pm
Reply with quote

Hello,

Suggest you clarify your latest post.

Nearly everyone has "SELECT on SYSIBM.SYSDUMMY1 table" and the question before this is not clear. . .
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Tue May 05, 2009 2:45 am
Reply with quote

In SQL, Date maths are limited. Check here for detailed information.

Maybe also look here to see some values to put after your SELECT.

For example (to calculate the first day of next month):
Code:
SELECT
    LAST_DAY(CURRENT DATE) + 1 DAY
INTO
    :WS-BEG-NEXT-MO
FROM
    SYSIBM.SYSDUMMY1
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Amount of days between two dates PL/I & Assembler 8
No new posts Arithmetic division using Syncsort SYNCSORT 6
No new posts Help this REXX Rookie-Bad arithmetic ... CLIST & REXX 7
No new posts Bad arithmetic conversion when assign... CLIST & REXX 4
No new posts HEADER1 with Date arithmetic DFSORT/ICETOOL 4
Search our Forums:

Back to Top