Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old November 13th, 2009, 05:56 AM
Friend of Wrox
Join Date: Jan 2007
Posts: 115
Thanks: 2
Thanked 0 Times in 0 Posts
Question Week Number of day, like VB Function DATEPART

Hi, I need help.

I need to get the week number of day,

like the VB Function:
 DATEPART("ww", Now())
I tried this but it does not calculate correctly as when the 1st is on Saterday (week1) & calculates on the 3rd Monday
the below code sees it as still part of week1 & not week 2
  WeekOfYear = Convert.ToString(Math.Ceiling(Convert.ToDouble(ManufactureDateVar.DayOfYear) / 7));
I need to somehow replicate the VB Function in C# to the correct week number
Please Assist!
Old November 13th, 2009, 09:12 AM
Friend of Wrox
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts

Please check the following:
int WeekoftheYear = Thread.CurrentThread.CurrentCulture.Calendar.GetWeekOfYear(DateTime.Now, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Saturday);
TextBox1.Text = WeekoftheYear.ToString();

Om Prakash Pant
Click the "Thanks" button if this post helped you.
Old November 13th, 2009, 09:29 AM
Friend of Wrox
Join Date: Jan 2007
Posts: 115
Thanks: 2
Thanked 0 Times in 0 Posts

Great Stuff - Thank You very much...

I appreciate your time & help

works nice - so much better than my previous calculation.

Thank You :)

Similar Threads
Thread Thread Starter Forum Replies Last Post
getting the same day of the week. crabjoe Classic ASP Basics 3 February 27th, 2008 12:45 PM
DAY of the week wdepreter Excel VBA 3 February 7th, 2007 06:44 AM
Day of week finder mrjaygreene Classic ASP Basics 6 May 13th, 2006 04:43 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.