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

Week of the month.

Status
Not open for further replies.

check75

IS-IT--Management
Dec 12, 2000
3
0
0
US
Hi

Need to know how can I calculate week of the month of the date given by the user, either in crystal reports or SQL Server. Working with Seagate Crystal Report 7.0.

eg. Date: March 6th 2001.
I need to know its second week of march.

Thanks
Kamal
 
When does the first week end?

First Sat?
First Sun?
Ken Hamady
Crystal Reports Training/Consulting and a
Quick Reference Guide to VB/Crystal (including ADO)
 
Saturday. Assuming Mar 1, Mar 2 First week.

March 5th to March 9th Second week.
 
If Sunday is the first day of the week, here is a formula you can use:

(Day({table.datefield}) + (7 - DayOfWeek({table.datefield}) - 1)) / 7


If Sunday is not the first day, you may need to tweek it some. THe DayOfWeek function counts sunday to saturday (1 to 7)
 
Disregard that first formula, it does not work under any circumstances (unless you round, but it will not always work). I was typing it out of memory while sitting here with a head cold (poor excuse).

Try this formula:

(Day({Table.Date}) + (7 - DayOfWeek({Table.Date}) + DayOfWeek(Date(Year({Table.Date}), Month({Table.Date}), 1)) - 1)) / 7

Again, this will only work if your week starts on Sunday. If it works on a different day, some tweaking will be needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top