King Erik I Posted April 20, 2004 Posted April 20, 2004 Hey, Here me is again :o) I want to get the DayOfWeek from the first day of any month.... I've got something like this: Dim iDowStart As Integer iDowStart = DateTime.Parse(Now.Year + "/" + Now.Month + "/01").DayOfWeek This isn't working. Does somebody knows a solution for this problem? [offtopic]When i previewed my post, explorer crashed :confused: [/offtopic] Thanks in advance, Quote
*Experts* mutant Posted April 20, 2004 *Experts* Posted April 20, 2004 (edited) Whhat do you mean it doesn't work? Do you want it to return a string with the day name instead of a number? Then declare your variable that stores the result as DayOfWeek enum. Dim f As DayOfWeek f = DateTime.Parse(Now.Year.ToString() & "/" & Now.Month.ToString() & "/01").DayOfWeek Then you can use the ToString method of the DayOfWeek variable to return a string representation of the day. Edited April 20, 2004 by mutant Quote
King Erik I Posted April 20, 2004 Author Posted April 20, 2004 No... i want the number of that day.... sunday = 1, monday = 2, e.g. I am writing a calendar for a pocket pc and i don't wanna use 3rd party components. Any suggestions maybe? Quote
*Experts* Nerseus Posted April 20, 2004 *Experts* Posted April 20, 2004 Actually, if you need to worry about globalization - or if you just want to see a full .NET version, try something like this: DateTime date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); string s = System.Globalization.DateTimeFormatInfo.CurrentInfo.DayNames[(int)date.DayOfWeek]; My VB version might not be 100% - in fact, I don't know how you cast from one type to another in VB. Below, change the "(int)" in front of "date.DayOfWeek" to however you cast in VB. Dim date As DateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1) Dim s As String = System.Globalization.DateTimeFormatInfo.CurrentInfo.DayNames((int)date.DayOfWeek) -Ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
King Erik I Posted April 20, 2004 Author Posted April 20, 2004 Typecasting (int) doen't work here. When i leave it, i will get the name of the day. int(date.DayOfWeek)) also doesn't work... I need the day number. p.s. date is reserved word :-) Quote
JumpsInLava Posted April 20, 2004 Posted April 20, 2004 Your original code didn't work, because you were using the plus instead of the ampersand. Dim iDowStart As Integer iDowStart = DateTime.Parse(Now.Year & "/" & Now.Month & "/01").DayOfWeek Note: Sunday = 0 If you want to be one based then: iDowStart += 1 Quote
King Erik I Posted April 20, 2004 Author Posted April 20, 2004 Aha.... i was very close to the solution. ;-) thanks a lot. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.