Re: String to Date
- From: "Rick Rothstein [MVP - Visual Basic]" <rickNOSPAMnews@xxxxxxxxxxxxxxxxx>
- Date: Sat, 25 Feb 2006 03:51:24 -0500
I need to find out what day of the week is the first day
of the year. Like this you it would be 1. I have this but
how can I convert the sting to a date?
Dim thisyear As Date
thisyear = Year(Now())
thisyear = "1/01/" & thisyear
thisyear = Weekday(thisyear)
I am a little confused by the wording of your question. First off, if the
"thisyear" variable is declared as a date, then your first assignment to it
would not make sense. Year(Now) is not a date value. For the way you have
structured your question, you could do this directly...
thisyear = "1/01/" & Year(Now)
but I don't recommend handling it this year. Better would be to use the
DateSerial function...
thisyear = DateSerial(Year(Now), 1, 1)
Another part of your question that confuses me involves your call to the
WeekDay function. Are you perhaps asking how to get the name of the day
(that is, "Sunday" instead of "1")? If so...
WD = WeekDayName(WeekDay(thisyear))
where thisyear has already been assigned the output from the DateSerial
call. WD, a STRING variable, will be assigned the text string "Sunday".
There is an optional argument available if you want the name abbreviated;
hence
WD = WeekDayName(WeekDay(thisyear), True)
assigns "Sun" to the String variable WD. There is one other way to do this
also...
WD = Format$(thisyear, "ddd")
assigns "Sun" to WD whereas
WD = Format$(thisyear, "dddd")
assigns "Sunday".
If none of this is what you were after, then you will need to state your
question more carefully.
Rick
Do you mean you want to know the day's name (like Monday, Tuesday, etc)? If
that is what you are asking then
.
- Follow-Ups:
- Re: String to Date
- From: Rick
- Re: String to Date
- References:
- String to Date
- From: Rick
- String to Date
- Prev by Date: String to Date
- Next by Date: Re: VB6, VB2005, or Something Else?
- Previous by thread: String to Date
- Next by thread: Re: String to Date
- Index(es):