ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » how to find the number of days between two dates

Post new topic  Reply to topic
 how to find the number of days between two dates « View previous topic :: View next topic » 
Author Message
gus
PostPosted: Wed Oct 04, 2006 4:59 am    Post subject: how to find the number of days between two dates Reply with quote

Apprentice

Joined: 10 Apr 2002
Posts: 36

Good morning,

I am trying to use CAST two dates as INTERVAL DAY to find the number of days between the two dates and having no luck at all. The date formats are '2006-09-29' and 2006-10-03' These are only examples. They can be any valid dates. Has anyone done this before. Any help would be great.
Back to top
View user's profile Send private message
Edde
PostPosted: Wed Oct 04, 2006 5:14 am    Post subject: Re: how to find the number of days between two dates Reply with quote

Acolyte

Joined: 01 Oct 2006
Posts: 67
Location: Moscow, Russia

Try to use EXTRACT function with DAYS option.

But it seems INTERVAl must work correct.
Can you give an example of your source code?
Back to top
View user's profile Send private message
gus
PostPosted: Wed Oct 04, 2006 6:22 am    Post subject: Reply with quote

Apprentice

Joined: 10 Apr 2002
Posts: 36

I got it working now. What a pain. You would think there would be better built in functions for dates. Here is what I did

DECLARE in_date DATE;
DECLARE curr_date DATE;
DECLARE numOfDays INT;
SET in_date = SUBSTRING(acctListRef."acctItem"[loopSub]."acctOpenDt" FROM 1 FOR 4) || '-' ||
SUBSTRING(acctListRef."acctItem"[loopSub]."acctOpenDt" FROM 5 FOR 2) || '-' ||
SUBSTRING(acctListRef."acctItem"[loopSub]."acctOpenDt" FROM 7 FOR 2);
SET curr_date = SUBSTRING(hostDate FROM 1 FOR 4) || '-' ||
SUBSTRING(hostDate FROM 5 FOR 2) || '-' ||
SUBSTRING(hostDate FROM 7 FOR 2);
SET numOfDays = CAST((curr_date - in_date) DAY AS INT);
Back to top
View user's profile Send private message
Edde
PostPosted: Wed Oct 04, 2006 6:36 am    Post subject: Reply with quote

Acolyte

Joined: 01 Oct 2006
Posts: 67
Location: Moscow, Russia

You can use CAST with FORMAT specified, for example:

SET in_date = CAST (acctListRef."acctItem"[loopSub]."acctOpenDt" AS DATE FORMAT 'yyyyMMdd')
Back to top
View user's profile Send private message
Vitor
PostPosted: Wed Oct 04, 2006 6:46 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Why not just subtract the dates? CASTing as necessary?

Or am I missing the obvious?
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Edde
PostPosted: Wed Oct 04, 2006 6:50 am    Post subject: Reply with quote

Acolyte

Joined: 01 Oct 2006
Posts: 67
Location: Moscow, Russia

Vitor wrote:
Why not just subtract the dates? CASTing as necessary?

Or am I missing the obvious?


You can substract dates, if you have dates.
But you cannot substract strings...

P.S. I understand. Substracting two dates you have INTERVAL, not INTEGER.
Back to top
View user's profile Send private message
Vitor
PostPosted: Wed Oct 04, 2006 7:04 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Point taken, but cast as dates (using your method), subtract & recast from INTERVAL to INTEGER if you don't fancy the implicit cast seems (IMHO) easier than all the substringing and contatenating. Certainly less typing!
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Edde
PostPosted: Wed Oct 04, 2006 7:21 am    Post subject: Reply with quote

Acolyte

Joined: 01 Oct 2006
Posts: 67
Location: Moscow, Russia

Vitor wrote:
Point taken, but cast as dates (using your method), subtract & recast from INTERVAL to INTEGER if you don't fancy the implicit cast seems (IMHO) easier than all the substringing and contatenating. Certainly less typing!


Totally agree
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » how to find the number of days between two dates
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.