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

dateinterval

Status
Not open for further replies.

confuseddddd

Programmer
May 22, 2003
53
US
Trying to find the current week number of the year and I am trying to use dateinterval.weekofyear; however system should be returning 14 and is returning 5. Any idea as to why???
Dim nWeek As Integer = DateInterval.WeekOfYear
also tried
Dim sWeek As String = DateInterval.WeekOfYear

Want to be able to get current week of year and then subtract a number from it to get previous week's of the year.
Any help would be great.
 
DateInterval.WeekOfYear is just an enumeration item so all you're returning is the value of WeekOfYear in the enumeration

You need...

Code:
dim sWeek as string=format(datepart(dateinterval.weekofyear,now)

For returning differences in dates see the DateDiff and DateAdd Functions
 
Use the GetWeekOfYear method that is on the System.Globalization.Calendar object.
Code:
Imports System.Globalization

Dim myCI As New CultureInfo("en-US")
Dim myCal As Calendar = myCI.Calendar
      
Dim myCWR As CalendarWeekRule = myCI.DateTimeFormat.CalendarWeekRule
Dim myFirstDOW As DayOfWeek = myCI.DateTimeFormat.FirstDayOfWeek

Console.WriteLine("Therefore, the current week is Week {0} of the current year.", myCal.GetWeekOfYear(DateTime.Now, myCWR, myFirstDOW))

____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Jeez chiph you're getting old. three times the same answer.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Getting impatient in my old age, posting before checking what forum I'm in.
[spineyes]

Hmmm. No response from confuseddddd.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top