Home > Archive > Visual Basic > February 2006 > String to Date
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| I need to find out what day of the w 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 = W day(thisyear)
Any help would be much appreciated!!
Rick
| |
| Rick Rothstein [MVP - Visual Basic] 2006-02-25, 3:55 am |
| > I need to find out what day of the w 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 = W day(thisyear)
I am a little 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
W Day function. Are you perhaps asking how to get the name of the day
(that is, "Sunday" instead of "1")? If so...
WD = W DayName(W Day(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 = W DayName(W Day(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
| |
|
|
|
| Yes I forgot I was playing with the thisyear being a date that did not work
as you can see. I started out with it as a string.
But this is more than enough to get me where I need to be thanks very much
for taking the time to help!!!
"Rick Rothstein [MVP - Visual Basic]" <rickNOSPAMnews@NOSPAMcomcast.net>
wrote in message news:%23BoOpieOGHA.1192@TK2MSFTNGP11.phx.gbl...
>
> I am a little 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
> W Day function. Are you perhaps asking how to get the name of the day
> (that is, "Sunday" instead of "1")? If so...
>
> WD = W DayName(W Day(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 = W DayName(W Day(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
>
>
>
| |
|
| Thanks!!!
"J French" <erewhon@nowhere.uk> wrote in message
news:44002f0d.166631840@news.btopenworld.com...
> On Fri, 24 Feb 2006 22:44:18 -0800, "Rick" <rick@di-wave.com> wrote:
>
>
> One way :-
>
> ThisYear = DateSerial( Year( Now ), 1, 1 )
> ThisW Day = W Day( ThisYear )
>
> As this looks like homework, I've shown you this in order that you do
> the following in the future :-
>
> a) Using 'string' Dates unless you really have to
> b) Avoid Locale affected functions
> c) Avoid coercion
>
>
| |
|
|
--
efi
"Rick" wrote:
> I need to find out what day of the w 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 = W day(thisyear)
>
> Any help would be much appreciated!!
>
> Rick
>
>
>
|
|
|
|
|