How to get Week Day from Date using VB.Net

Discussion in 'ASP .Net' started by Kiran, Jun 20, 2005.

  1. Kiran

    Kiran Guest

    Hi,

    DateVal.DayOfWeek returns an integer value(0-6) that represents days from sun-sat.

    Is there a way to get the Day(like sunday, monday) from a Date Variable using VB.Net without using a switch case after getting the integer value from DateVal.DayOfWeek, some sort of direct way.

    Thanks
    Kiran
    Kiran, Jun 20, 2005
    #1
    1. Advertising

  2. Kiran

    Hans Kesting Guest

    So you have an integer, and you want a text, representing the day?
    You could define a string-array holding all 7 names and use the
    number as index into that array.

    Or more directly (but english only):
    DayOfWeek does *not* return an integer, it returns a value from the DayOfWeek
    enumeration (which can translate into that integer)! If you do a "ToString()" on that enum,
    you should end up with the dayname.

    Hans Kesting

    "Kiran" <> wrote in message news:%23lVU$...

    Hi,

    DateVal.DayOfWeek returns an integer value(0-6) that represents days from sun-sat.

    Is there a way to get the Day(like sunday, monday) from a Date Variable using VB.Net without using a switch case after getting the integer value from DateVal.DayOfWeek, some sort of direct way.

    Thanks
    Kiran
    Hans Kesting, Jun 20, 2005
    #2
    1. Advertising

  3. Kiran

    Derek Harmon Guest

    "Hans Kesting" <> wrote in message news:%...
    > So you have an integer, and you want a text, representing the day?
    > You could define a string-array holding all 7 names and use the
    > number as index into that array.


    There is of course a built-in array for this purpose in System.Globalization,

    CultureInfo.CurrentCulture.DateTimeFormat.DayNames( dayOfWeekNumber)

    > If you do a "ToString()" on that enum, you should end up with the dayname.


    You're correct that the Enum's identifiers are in English only. However, if
    he calls ToString( ) on the original DateTime he can get the day's name in
    his current thread's language:

    dateTime.ToString( "dddd") ' dddd is the date/time format for the day

    On an en-US web server this will be "Monday," whereas on an es-ES server
    this will be "lunes."


    Derek Harmon
    Derek Harmon, Jun 20, 2005
    #3
  4. <%@ Page Language="VB" %>
    <script language="VB" runat="server">
    Sub Page_Load
    Dim dt As New DateTime(2005, 6, 20)
    Response.Write( dt.DayOfWeek.ToString())
    End Sub
    </script>
    <html>
    <body>
    </body>
    </html>



    Juan T. Llibre
    ASP.NET MVP
    http://asp.net.do/foros/
    Foros de ASP.NET en EspaƱol
    Ven, y hablemos de ASP.NET...
    ======================

    "Kiran" <> wrote in message
    news:%23lVU$...

    Hi,

    DateVal.DayOfWeek returns an integer value(0-6) that represents days from sun-sat.

    Is there a way to get the Day(like sunday, monday) from a Date Variable using VB.Net
    without using a switch case after getting the integer value from DateVal.DayOfWeek, some
    sort of direct way.

    Thanks
    Kiran
    Juan T. Llibre, Jun 20, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    3
    Views:
    1,829
    Alexandre
    Dec 22, 2003
  2. Lew
    Replies:
    0
    Views:
    357
  3. Guest
    Replies:
    3
    Views:
    518
    Alexandre
    Dec 22, 2003
  4. Guest
    Replies:
    3
    Views:
    1,077
    Alexandre
    Dec 22, 2003
  5. get the week day of a date?

    , Mar 6, 2007, in forum: Perl Misc
    Replies:
    2
    Views:
    85
    Mumia W.
    Mar 6, 2007
Loading...

Share This Page