Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo

  Week date (Thursday, January 27, 2005)




Found the following interesting discussion in the Newsgroups:

Week date
by:simon

If I have week number for example: 24
how can I get start(monday) and end(sunday) date?

Thank you,
Simon


 Reply:
by:gani

 simon,

i'm not sure if there's a built-in funtionality
in .net to solve your problem. in case there's none, you
can try this one.

Dim dt as new DateTime
(DateTime.Now.Year,1,1)
Dim week_number as Integer = 1 'change
week number
Dim days_in_week as Integer = 7
Dim start_date as String
Dim end_date as String
dt = dt.AddDays(( (week_number-1) *
days_in_week) - 1)

While ((dt.DayOfWeek <> DayOfWeek.Monday))
dt = dt.AddDays(-1)
End While

start_date = dt.ToShortDateString()
end_date = dt.AddDays(days_in_week-
1).ToShortDateString()

Console.WriteLine("Start: {0} | End:
{1}",start_date, end_date)

HTH

gani
http://thedeveloperscorner.com.ph


 Reply:
by:Jay B. Harlow [MVP - Outlook]

 Gani,
That's about what I was going to say.

However you don't really need the While loop, you can use:

dt = dt.AddDays(dt.Monday - dt.DayOfWeek)

To get the same effect.

Hope this helps
Jay








0 Comments:

Post a Comment

 
Previous Posts
    - If only MSDN examples would actually work!
    - How to use managed code in Office 2003
    - Click Event not fired
    - How to read a particular setting from a file
    - Distinct groupid
    - How to pass Control Parameters between Forms
    - How to fill multi dimensional array
    - Array of Properties ??? Please Help
    - New to VB.NET - Active Directory
    - Windows Explorer API or Namespace??

Archives
    - 10/03/2004 - 10/10/2004
    - 10/10/2004 - 10/17/2004
    - 10/17/2004 - 10/24/2004
    - 10/24/2004 - 10/31/2004
    - 10/31/2004 - 11/07/2004
    - 11/21/2004 - 11/28/2004
    - 11/28/2004 - 12/05/2004
    - 12/05/2004 - 12/12/2004
    - 12/12/2004 - 12/19/2004
    - 12/19/2004 - 12/26/2004
    - 12/26/2004 - 01/02/2005
    - 01/23/2005 - 01/30/2005
    - 01/01/2006 - 01/08/2006
    - 09/24/2006 - 10/01/2006

Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland