Results 1 to 8 of 8

Thread: [2005] Clarity on date Objects

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    384

    [2005] Clarity on date Objects

    How can I display a string like :

    Wednesday is the 5th day week of week number in 2007

    ?

    Is that even possible?

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    384

    Re: [2005] Clarity on date Objects

    OK, figured out how to show the week number.
    Code:
            Dim sWeekOfYear As Integer = D.DayOfYear
            Dim sWeek As Integer = (sWeekOfYear / 7)
            Label9.Text = "Week " & sWeek.ToString
    How can I show today's name, IOW, Wednesday ?

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Clarity on date Objects

    Date.Today.DayOfWeek.ToString()

    Also, note that, by many people's standards, the first week of the year is not simply the first 7 days. The first week of the year might have less than 7 days and it might start after the first of January, going by normal standards. Check out the CalendarWeekRule enumeration for more info.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    384

    Re: [2005] Clarity on date Objects

    Thanx for the info!
    I get week number 19, so it seems to be correct.
    One last question here, how do I display 'May' instead of 5 ?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    384

    Re: [2005] Clarity on date Objects

    Figured out how to display 'May' :
    Code:
    Microsoft.VisualBasic.DateAndTime.MonthName(number)
    Isn't there an easier way?

  6. #6
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872

    Re: [2005] Clarity on date Objects

    I gess:
    Code:
    Date.Today.Month.ToString()
    but i wasn't able to test/try it.
    - Use the thread tools to Mark your Thread as Resolved when your question is answered.
    - Please Rate my answers if they where helpful.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    384

    Re: [2005] Clarity on date Objects

    Thanx, but that still shows 5

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Clarity on date Objects

    If you want to format a date you use it's ToString method. "d" is for day, "M" is for month and "y" is for year. Where day and month is concerned you can specify 1, 2, 3 or 4 characters. 1 character is single digit, 2 characters is double digit (leading zero), 3 characters is abbreviated name and 4 characters is full name, e.g.
    vb Code:
    1. MessageBox.Show(Date.Today.ToString("dddd, d MMMM yyyy"))
    displays "Saturday, 12 May 2007".

    All this is in the MSDN library and if you'd searched for date format you'd have found it yourself.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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