-
Aug 1st, 2024, 05:46 AM
#1
Thread Starter
New Member
Opposite weekOfyear
Hi,
with this code I get the week number of the year:
Code:
Imports System.Globalization
Public Class Form1
Dim dateNow = DateTime.Now
Dim dfi = DateTimeFormatInfo.CurrentInfo
Dim calendar = dfi.Calendar
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' using Thursday because I can.
Dim weekOfyear = calendar.GetWeekOfYear(dateNow, dfi.CalendarWeekRule, DayOfWeek.Thursday)
Label1.Text = weekOfyear
End Sub
End Class
Should I do the opposite, that is, from the weekOfyear derive the date (dd/mm/yyyy)…? thanks..
-
Aug 1st, 2024, 07:11 AM
#2
Re: Opposite weekOfyear
Originally Posted by tomi24
Should I do the opposite
Do you actually mean "how can I do the opposite"? Assuming you do, how do you think you should do it? The logic should pretty simple so how about you put some thought into first and then ask us to help if it does work. You don't actually need any programming experience to come up with the logic, so anyone can do that. You just need to work out what the dates for the first week are, based on the day of the week the year starts on, and then add the appropriate multiple of 7 days. Make some effort on your own behalf first, then we can help you fix it if it doesn't work. You don't even know that you can't do it if you don't even try. Trying and failing is part of learning so, if you want to learn, don't avoid it.
-
Aug 2nd, 2024, 05:23 AM
#3
Thread Starter
New Member
Re: Opposite weekOfyear
Apart from the various formulas and logics etc… and this was quite simple…
I meant if there was a function already made like calendar.GetWeekOfYear that by giving the number of weeks and the year returned the date…
I was looking for something like this:
Code:
Label1.Text = DateAdd("ww", NSett - 1, DateSerial(Year(Now), 1, 1))
anyway thanks for the interest…
-
Aug 2nd, 2024, 07:31 AM
#4
Re: Opposite weekOfyear
What date should it return tho? At best it can only return the date of the beginning of the week... you can give GetWeekOfYear a date and it returns which week that date is on ... but given a week, you can't restore the original date. Also typical functions in libraries tend to be used a lot. My guess is that since people already have the date going from date to week of year is much more commonly done, than going the other way around.
-tg
-
Aug 2nd, 2024, 02:47 PM
#5
Re: Opposite weekOfyear
Originally Posted by tomi24
Apart from the various formulas and logics etc… and this was quite simple…
I meant if there was a function already made like calendar.GetWeekOfYear that by giving the number of weeks and the year returned the date…
I was looking for something like this:
Code:
Label1.Text = DateAdd("ww", NSett - 1, DateSerial(Year(Now), 1, 1))
anyway thanks for the interest…
I feel like I'm missing it, but is this what you want,
Code:
Public Function DateFromWeekNum(year As Integer, WeekNumber As Integer) As Date
Dim rv As New Date(year, 1, 1)
rv = rv.AddDays(WeekNumber * 7)
Return rv
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|