How to get Week Day from Date using VB.Net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kiran

    How to get Week Day from Date using VB.Net


    Hi,

    DateVal.DayOfWe ek 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.DayOfWe ek, some sort of direct way.

    Thanks
    Kiran
  • Hans Kesting

    #2
    Re: How to get Week Day from Date using VB.Net

    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" <kiran_nospam@g mail.com> wrote in message news:%23lVU$uWd FHA.1448@TK2MSF TNGP14.phx.gbl. ..

    Hi,

    DateVal.DayOfWe ek 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.DayOfWe ek, some sort of direct way.

    Thanks
    Kiran

    Comment

    • Derek Harmon

      #3
      Re: How to get Week Day from Date using VB.Net

      "Hans Kesting" <news.2.hansdk@ spamgourmet.com > wrote in message news:%23wVJATXd FHA.1220@TK2MSF TNGP10.phx.gbl. ..[color=blue]
      > 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.[/color]

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

      CultureInfo.Cur rentCulture.Dat eTimeFormat.Day Names( dayOfWeekNumber )
      [color=blue]
      > If you do a "ToString() " on that enum, you should end up with the dayname.[/color]

      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.ToStri ng( "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


      Comment

      • Juan T. Llibre

        #4
        Re: How to get Week Day from Date using VB.Net

        <%@ Page Language="VB" %>
        <script language="VB" runat="server">
        Sub Page_Load
        Dim dt As New DateTime(2005, 6, 20)
        Response.Write( dt.DayOfWeek.To String())
        End Sub
        </script>
        <html>
        <body>
        </body>
        </html>



        Juan T. Llibre
        ASP.NET MVP

        Foros de ASP.NET en EspaƱol
        Ven, y hablemos de ASP.NET...
        =============== =======

        "Kiran" <kiran_nospam@g mail.com> wrote in message
        news:%23lVU$uWd FHA.1448@TK2MSF TNGP14.phx.gbl. ..

        Hi,

        DateVal.DayOfWe ek 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.DayOfWe ek, some
        sort of direct way.

        Thanks
        Kiran


        Comment

        Working...