Page 1 of 1

Routine Help

Posted: Thu Jan 10, 2008 6:55 pm
by paddu
I need to identify "first Monday of the Month" .

Found below post very helpful

http://dsxchange.com/viewtopic.php?t=10 ... 2774003db1



DSguru2B - Your post was helpful . Your routine worked for me only when i removed the UPCASE out of the variable DayToFind.

Routine:

InDate = Iconv(Trim(Arg1),"DYMD")
DayToFind = (Trim(Arg2))
DayByName = ''
DayByNum= ''

DayByName = Oconv(InDate,"DWA")
DayByNum = Oconv(InDate,"D D")


If (DayByName = DayToFind AND DayByNum < 8 )
Then
Ans = @TRUE
END
Else
Ans = @FALSE
End



Please let me know if my understanding is wrong.

Appreciate your suggestions.
Thanks
Paddu

Posted: Thu Jan 10, 2008 7:02 pm
by ray.wurlod
Identify the first day of the month. Lots of ways to do this - for example look at the MONTH.FIRST Transform.

Determine the day of the week of that day. Again, lots of ways to do this, but Mod(TheDate, 7) is probably the most efficient. 0 is Sunday, 6 is Saturday.

Add the right number of days to the (internal format of) the date and you have the date of the first Monday of the month.

Make an attempt - if you can't get it to work post your code and we'll constructively criticize it.

Posted: Thu Jan 10, 2008 11:19 pm
by paddu
Ray,

Thanks for your quick response.

I need to check if the current date is first monday of the month in the job sequence . If true then start rest of the sequences else exit and send notification.

I am able to achieve using the routine DSguru2B posted.

If i understood your post correctly, you are suggesting to create a routine using the code of MONTH.FIRST transform and change it to achieve first monday of the month.

I will surely try and post my work .

Thanks
Paddu

Posted: Thu Jan 10, 2008 11:25 pm
by ray.wurlod

Code: Select all

Oconv(Date(), "D-YM[4,2]") : "-01"
yields the date of the first of the month. That should get you going.

Posted: Thu Jan 10, 2008 11:40 pm
by paddu
Really !!!!, Let me try this tomorrow .
Not at desk right now :)

Posted: Fri Jan 11, 2008 11:23 am
by paddu
ray.wurlod wrote:

Code: Select all

Oconv(Date(), "D-YM[4,2]") : "-01"
yields the date of the first of the month. That should get you going.

Ray,

I not trying to achieve date of first of the month from the current date.
Sorry i did not look into your post indetail before.

I am trying to see if the GIVEN_DATE (could be Current date ) is First Monday of the Month .

Thanks
Paddu

Posted: Fri Jan 11, 2008 1:46 pm
by kcbland
If your date in question is within the first 7 days of its month (day number is 1 thru 7) and the day of the week of your date is Monday, then logic would dictate that your date is the first Monday of its month.

If this is not right for your situation, then you need to clarify as I see two different requirements stated by you. If your processing requires you to confirm if a given date just happens to be the first Monday of its month, then my description above fits. If your processing requires you to confirm if a given date just happens to be the first Monday of the CURRENT month, that's a different scenario. Please clarify.

Posted: Fri Jan 11, 2008 3:02 pm
by paddu
kcbland wrote:If your date in question is within the first 7 days of its month (day number is 1 thru 7) and the day of the week of your date is Monday, then logic would dictate that your date is the first Monday of its month.

If this is not right for your situation, then you need to clarify as I see two different requirements stated by you. If your processing requires you to confirm if a given date just happens to be the first Monday of its month, then my description above fits. If your processing requires you to confirm if a given date just happens to be the first Monday of the CURRENT month, that's a different scenario. Please clarify.
My requirement needs to confirm if a given date just happens to be the first Monday of the CURRENT month in the job sequence to start rest of the sequences else exit the sequence.

Which i am able to achieve with the routine mentioned in my first post.

I was just trying the logic which ray mentioned in this thread.

Anyways my original post was to make sure i am not going wrong anywhere .
since my issue is resolved on my end , i better mark this thread resolved .

I hope this will make GURUS to focus on other posts.

Thanks
paddu

Posted: Fri Jan 11, 2008 3:36 pm
by ray.wurlod
Oconv(InLink.GivenDate, "D-YM[4,2]") : "-01" is the first day of its month if GivenDate is in internal format. If it is not, apply an approriate Iconv() to GivenDate within the Oconv() function.

The function I have already given is the first day of the current month.

The rest is arithmetic.