|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Day of week from date |
« View previous topic :: View next topic » |
Author |
Message
|
LH33 |
Posted: Wed Mar 05, 2003 2:02 pm Post subject: Day of week from date |
|
|
Master
Joined: 21 Nov 2002 Posts: 200
|
HI!
Is there a way to tell the day of the week from within WMQI? I have a need to calculate a date based on teh day of teh week.
Thanks, LisaB |
|
Back to top |
|
 |
kirani |
Posted: Thu Mar 06, 2003 6:59 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
Lisa,
I don't think there is any function in WMQI, which will return you DayOfWeek. I can think of two options,
1. Write a stored procedure, which calls a DB function (I am sure most of the databases will have this function). You would then call this stored procedure in your ESQL code.
2. Write your own esql code to calculate this. _________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
matthews |
Posted: Sat Mar 08, 2003 9:16 am Post subject: ESQL to identify the Day of the Week |
|
|
 Novice
Joined: 15 Apr 2002 Posts: 12
|
Lisa,
Here are two examples - one is written as a function and needs WMQI 2.1 CSD4 - because is is using one of the new features where one can DECLARE a varable name type and value, a simple example is
DECLARE x INT 1;
which saves the extra set x=1; step.
The second example (after the row of ========) is written as a procedure and will run on WMQI 2.1 CSD2 or later. This one does the caculation on a step by step basis and thus is easier to understand ...
This ESQL code is based on the technique discovered by Lewis Carol (author of Alice in Wonderland).
---------------------------------------------------------------------------
-- This Create Function example requires WMQI 2.1 CSD4
Set Environment.WeekDay = DayofTheWeek(Cast(Current_Date AS CHAR));
CREATE FUNCTION DayOfTheWeek (DateInC Char) RETURNS Char
BEGIN
Declare y Int Cast(Substring(DateInC From 9 for 2) as Int);
RETURN Case (Mod(((2 * (3 - Mod((Cast(Substring(DateInC From 7 for 2) as Int)), 4))) +
(Mod((y / 12) + mod(y, 12) + (Mod(y, 12) / 4), 7)) +
(Case (Cast(Substring(DateInC from 12 for 2) as Int))
when 1 then 0 when 2 then 3 when 3 then 3 when 4 then 6
when 5 then 1 when 6 then 4 when 7 then 6 when 8 then 2
when 9 then 5 when 10 then 0 when 11 then 3 when 12 then 5
End) +
(Mod((Cast(Substring(DateInC from 15 for 2) as Int)), 7))), 7))
When 0 Then 'Sun' When 1 Then 'Mon'
When 2 Then 'Tue' When 3 Then 'Wed'
When 4 Then 'Thu' When 5 Then 'Fri'
When 6 Then 'Sat' Else 'xxx'
End;
End;
================================================================================================================
-- This Create Procedure example will run with WMQI V2.1 CSD2 or later
Declare DateInC Char;
Set DateInC = Cast(Current_Date as Char);
Declare DayofWeek Char;
CALL DayOfTheWeek(DateInC,DayofWeek);
Set Environment.WeekDay = DayofWeek;
CREATE PROCEDURE DayOfTheWeek (IN DateInC Char, INOUT DayOut Char)
BEGIN
Declare C INT;
Declare Y Int;Declare M Int;Declare D Int;Declare DayI int;Declare DayOfWeek Char;
Declare c Int;Declare y Int;Declare m Int;Declare d int;
Set c = Cast(Substring(DateInC From 7 for 2) as Int);
Set y = Cast(Substring(DateInC From 9 for 2) as Int);
Set m = Cast(Substring(DateInC from 12 for 2) as Int);
Set d = Cast(Substring(DateInC from 15 for 2) as Int);
Set C = 2 * (3 - Mod(c, 4));
Set Y = Mod((y / 12) + mod(y, 12) + ( mod(y, 12) / 4), 7);
set M = Case m
when 1 then 0 when 2 then 3 when 3 then 3 when 4 then 6 when 5 then 1 when 6 then 4
when 7 then 6 when 8 then 2 when 9 then 5 when 10 then 0 when 11 then 3 when 12 then 5
End;
set D = Mod(d, 7);
Set DayI = Mod((C + Y + M + D), 7);
Set DayOut = Case DayI
When 0 Then 'Sun' When 1 Then 'Mon' When 2 Then 'Tue' When 3 Then 'Wed' When 4 Then 'Thu'
When 5 Then 'Fri' When 6 Then 'Sat' Else 'xxx'
END;
End; _________________ Bill Matthews
Certified MQ, MQSI, WMQI and Transaction Server |
|
Back to top |
|
 |
simon.starkie |
Posted: Sun Mar 09, 2003 5:24 pm Post subject: Java Calendar object? |
|
|
Disciple
Joined: 24 Mar 2002 Posts: 180
|
This may be a little over the top, but you could write a custom plugin in Java and get the functionality you need from a Java Calendar object... |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|