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?
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.
MyDate. ToString("dddd") will get you what you want.
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)
Label1.Text = Date.Today.ToString("dddd")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With