2
Answers

WEEK NUMBER OF YEAR

Photo of Marvin kakuru

Marvin kakuru

14y
2.7k
1
hi there,

i am trying to get a textBox.text to show the WEEK NUMBER OF YEAR as at the datetime.now how can i do this

this is the code i am using to show the date AND time.

textBox.text = Datetime.Now.ToString();

any help??

Answers (2)

1
Photo of Vulpes
NA 98.3k 1.5m 14y
It depends exactly what you mean by 'week number of year' but, taking the first week as 1 Jan to 7 Jan, the second week as 8 Jan to 14 Jan and so on, then the following should work:

        DateTime today = DateTime.Today;
        DateTime start = new DateTime(today.Year, 1, 1);
        int weekOfYear = (today - start).Days/7 + 1;
        textBox.Text = weekOfYear.ToString();
Accepted
0
Photo of Marvin kakuru
NA 224 113.4k 14y
THANKS ALOT VULPES IT WORKED JUST LIKE NEEDED.
BEST REGARDS