Saturday, March 31, 2012

set a date value

Dear sir,
We are on the w of 27 in year 2004. So this w is "2004-27", last w
is "2004-26",
My question is how can I get the first sunday of w "2004-26", how can I
change string "2004-26" into a DateTime variable with the value of first
sunday of w 2004-26?
Kind regards
Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.comThe easiest way I could think of would be to check what the first day of the
year is (1/1/2004) through the DayOfW property of the DateTime class and
calculate the offset between it and the previous Sunday.
For 2004, calling DateTime.DayOfW for 1/1/2004 would return Thursday.
Therefore, the first w of 2004 (by w numbers) started on Sunday,
12/28/2003. To determine the Sunday starting any given w during 2004 you
could simply calculate it via:
public DateTime GetWStart(int WNumber)
{
return FirstSundayOfYear.AddDays(7*(WNumber-1));
}
The rationale for (WNumber-1) is that the FirstSundayOfYear would already
be set to 12/28/2003 so if you were looking for w 1 then you would want
to add 0 days as opposed to 7.
You indicated that you wanted to convert a string (2004-26) into a DateTime
for the first sunday of each w. What I would probably do in this
scenario since obviously no direct conversion exists would be to define a
WDictionary class derived from System.Collections.DictionaryBase and set
the key of the key to the desired string and the value to the appropriate
DateTime value.
Hope this helps!
"Guoqi Zheng" <no@.sorry.nl> wrote in message
news:uIdNKvDXEHA.128@.TK2MSFTNGP10.phx.gbl...
> Dear sir,
> We are on the w of 27 in year 2004. So this w is "2004-27", last
w
> is "2004-26",
> My question is how can I get the first sunday of w "2004-26", how can I
> change string "2004-26" into a DateTime variable with the value of first
> sunday of w 2004-26?
> --
> Kind regards
> Guoqi Zheng
> guoqi AT meetholland dot com
> Http://www.meetholland.com
>
>

0 comments:

Post a Comment