Would anyone know how to convert any date first into a Saturday and then into yyww (weekyear) in VB.NET? And vice versa, ie yyww into a Saturday?
I first need to convert a date into the Saturday of that week, then convert the Saturday into yyww. Otherwise, just converting a date into yyww will not return consistent results.
Greg
2009-03-20 15:49:15
+2
A:
Assuming your weeks start on Sunday, you could probably do something like this to get the saturday of the current week:
Dim daysToAdd As Integer = DayOfWeek.Saturday - yourDate.DayOfWeek
Dim dateSaturday as Date = yourDate.AddDays(daysToAdd)
I didn't test it though. Then you could get the weekyear by doing something like:
Dim weekYear As Integer = CInt(Math.Ceiling(dateSaturday.DayOfYear / 7))
Using the reverse logic you can find the saturday corresponding to the weekyear.
Meta-Knight
2009-03-20 18:56:00
+2
A:
Dim d As DateTime = #1/20/2009#
d = d.AddDays(DayOfWeek.Saturday - d.DayOfWeek)
Dim myCal As New System.Globalization.GregorianCalendar
Dim wkOFyr As Integer = myCal.GetWeekOfYear(d, _
Globalization.CalendarWeekRule.FirstDay, _
DayOfWeek.Sunday)
Dim s As String
s = d.ToString("yy") & wkOFyr.ToString.PadLeft(2, "0"c)
dbasnett
2009-03-21 12:38:21