Results 1 to 6 of 6

Thread: Week Number From Date

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Week Number From Date

    This is driving me towards lunacy

    How can I get the week number from a datetime type ?

    Any Ideas ?
    There must be a nice simple, refined way to do this.

    TIA

    Parksie

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Week Number From Date

    Quote Originally Posted by venerable bede
    This is driving me towards lunacy

    How can I get the week number from a datetime type ?

    Any Ideas ?
    There must be a nice simple, refined way to do this.

    TIA
    VB Code:
    1. Imports System.Globalization
    2.  
    3. '...
    4.  
    5. Dim myCI As New CultureInfo("en-US")    'defines the calendar system.
    6. Dim myCal As Calendar = myCI.Calendar
    7. messagebox.show(myCal.GetWeekOfYear(Date.Today, CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday))

    Dolly Dimple

    If I helped you rate me, if I didn't then don't
    I don't live here any more.

  3. #3

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Re: Week Number From Date

    Thanks Wossy but I already tried that from the MSDN but I keep getting the error :

    Calendar is ambiguous, imported from the namespaces or types, ' System.Globalization, System.UI.WebControls'

    and before you say it, I have imported the Globalization namespace at the top of my page.

    This doodles my dingo

    Parksie

  4. #4
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Week Number From Date

    OK, well fully qualify the class names then...

    VB Code:
    1. Dim myCI As New System.Globalization.CultureInfo("en-US")         'defines the calendar system.
    2.         Dim myCal As System.Globalization.Calendar = myCI.Calendar
    3.  
    4.         messagebox.show(myCal.GetWeekOfYear(date.today, System.Globalization.CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday))

    Ambiguous names can be solved by fully qualifying the namespace explicitly.
    I don't live here any more.

  5. #5

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Resolved Re: Week Number From Date

    Any Idea why you have to qualify the namespace explicitly ?
    Strange.

    Anyways, thnx wossy.
    I'm glad I am carrying your baby.

    Parksie

  6. #6
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Week Number From Date

    Quote Originally Posted by venerable bede
    Any Idea why you have to qualify the namespace explicitly ?
    Strange.
    Its not strange really its just that 2 namespaces (both of which you have imported in yout app) both have a class called Calendar. Its like someone saying "I'm flying to Aberdeen". The compiler thinks: "Which one? The one in Scotland or the one in America?" So you have to say it longhand: "I'm flying to Scotland.Aberdeen".

    Its perfectly legal to have 2 classes with the same name as long as they are in different namespaces. This is also possible if one namespace CONTAINS the other namespace (nested). A long as you qualify it then there is no problem.

    NOTE: If there is a name conflict and the namespace is really long then you can do this:

    VB Code:
    1. Imports Woss = System.Drawing.Drawing2D

    The word "Woss" then becomes a shorthand way of writing that long namespace Cool eh?
    Then use the 'alias' to make life easier...

    VB Code:
    1. Dim gr as Woss.Graphics
    2. 'this is equivalent to...
    3. Dim gr as System.Drawing.Drawing2D.Graphics



    PS, I can think of no better mother for my children. I hope its twins.
    I don't live here any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width