Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get week of the month from a given date?

Status
Not open for further replies.

sekar211

MIS
Dec 15, 2003
55
US
I have a table with date column in it (MM/DD/YYYY).i want week of the month to be displayed on the report and i am using applysimple("datepart(wk,datepart(month,#0)",givendate) but i am not getting the correct values.
am i doing it in the right way?

Thank you,
Puneeth
 
This probably isn't the best solution but it looks like it works but I haven't tested it for very many dates. Either way it should put you in the right direction.

ApplySimple("datepart(dd,#0)/7 +1", [givendate])

 
I tried your applysimple and it is working good.Thank you.
But now the user requirement has changed and they are asking for weekending date to be displayed on the report.so i am thinking of creating a new table with weekending column in it.is it the correct way to do it? or is there any other way we can do in MSTR itself with out creating a table?

Once again Thank you very much.
 
My preference is to use a time table supplied by the RDBMS if it's available. Teradata example: RDBMS ships with sys_calendar. I usually query to or join to that.

Code:
select week_of_month, week_of_year from sys_calendar.CALENDAR where calendar_date = '2004-08-30'

Results:
week_of_month week_of_year
5 35
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top