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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Week Number of Month by Day 1

Status
Not open for further replies.

ToneV

MIS
Oct 29, 2003
19
US
I am looking for a formula that calculates the week number of the month by day. For example, Wednesday, December 21 is the 3rd Wednesday of the month (3) and Thursday, December 22 is the 4th Thursday of the month (4), etc... Any help would be appreciated.
 
After further review, this is great for getting the week number. However, for example, although Dec. 21 falls into the 4th week, it is still the 3rd Wednesday of the month. This formula is pulling in a 4 rather than a 3 in this example.
 
Try this:
Code:
Local DateVar dt := PrintDate ; //Whatever Date you need would go here
Local DateVar first := dt-Day(dt)+1 ;
Local NumberVar daynum := DayOfWeek(dt) ;
Local Numbervar howmany := DateDiff('ww',first,dt,daynum) ;

howmany := ( if DayofWeek(first)=daynum then howmany +1 else howmany ) ;

"This is the " & ToText(howmany,0)
& (
Select howmany 
case 1 : "st " 
case 2 : "nd "
case 3 : "rd "
default : "th "
)
& WeekdayName (daynum)
& " in "
& ToText(dt,"MMMM")

Bob Suruncle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top