Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vb.net getting weekday name

Tags:

vb.net

Today is 21.10.2012. and it is Sunday.
But my VB.NET think different:

Debug.Print("Weekday for the date '21.10.2012.'is " & WeekdayName(Weekday("21.10.2012.")))
Debug.Print("Weekday for the date '21/10/2012'is " & WeekdayName(Weekday("21/10/2012")))
Debug.Print("Weekday for the date '" & DateTime.Now.Date & "'is " & WeekdayName(Weekday(DateTime.Now.Date)))

All those 3 checks give me: 'Monday' for weekday name!
What to do to get proper weekday names?

like image 678
Wine Too Avatar asked Oct 20 '12 23:10

Wine Too


People also ask

How to get day of week in VB net?

Use the DateTime. DayOfWeek or DateTimeOffset. DayOfWeek property to retrieve a DayOfWeek value that indicates the day of the week. If necessary, cast (in C#) or convert (in Visual Basic) the DayOfWeek value to an integer.

How extract day from date in VB net?

MyDate. ToString("dddd") will get you what you want.


2 Answers

This is the correct .NET way to get the weekday name of a given date:

Dim myCulture As System.Globalization.CultureInfo = Globalization.CultureInfo.CurrentCulture
Dim dayOfWeek As DayOfWeek = myCulture.Calendar.GetDayOfWeek(Date.Today)
' dayOfWeek.ToString() would return "Sunday" but it's an enum value,
' the correct dayname can be retrieved via DateTimeFormat.
' Following returns "Sonntag" for me since i'm in germany '
Dim dayName As String = myCulture.DateTimeFormat.GetDayName(dayOfWeek)
like image 160
Tim Schmelter Avatar answered Oct 06 '22 21:10

Tim Schmelter


 Label1.Text = Date.Today.ToString("dddd")
like image 34
Dev_Manager Avatar answered Oct 06 '22 22:10

Dev_Manager