How to get Week Day from Date using VB.Net

K

Kiran

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
 
H

Hans Kesting

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


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
 
D

Derek Harmon

Hans Kesting said:
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
 
J

Juan T. Llibre

<%@ 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>






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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top