Octavio,
You know, in the back of my mind I was thinking modulus, but it just
didn't
click when I was typing...
Thanks for the additional.
Jay
| Jay,
|
| I use more-less the same technique you describe, only I use a modulus
op:
|
| dow = dow % 7;
|
| instead of:
|
| if (dow < 0) dow += 7;
|
| I guess your version performs better...
|
| Regards - Octavio
|
| "Jay B. Harlow [MVP - Outlook]" <
[email protected]> escribió en el
| mensaje | > Simon,
| > | Is there any way to do that in C#?
| > Yes, As Nicholas stated: add a reference to the
Microsoft.VisualBasic.dll
| > and call Microsoft.VisualBasic.DateAndTime.DatePart!
| >
| >
| > As to your original question DateTime.DayOfWeek returns the DayOfWeek
Enum
| > with values such as Monday, Tuesday, Wednesday, making
DateTime.DayOfWeek
| > literal which day of the week it is, and not some offset from some
| > arbitrary
| > "FirstDayOfTheWeek". So DateTime.DayOfWeek will return
DayOfWeek.Monday
| > when
| > its Monday!
| >
| > Fortunately the DayOfWeek enum values are consecutive, so if you want
to
| > convert the DayOfWeek enum to & from an integer value where 0 means
| > Monday,
| > you can use simply comparisons & arithmetic to reimplement the aspect
of
| > Microsoft.VisualBasic.DateAndTime.DatePart you are looking for...
| >
| > Something like:
| >
| > static Int16 OffsetFromFirstDayOfWeek(DateTime theDate, DayOfWeek
| > firstDayOfWeek)
| > {
| > Int16 dow = (Int16)((Int16)theDate.DayOfWeek -
| > (Int16)firstDayOfWeek);
| > if (dow < 0)
| > dow += 7;
| > return dow;
| > }
| >
| >
| > DateTime sellDate = DateTime.Now;
| > Int16 dayOfWeek;
| >
| > dayOfWeek = OffsetFromFirstDayOfWeek(sellDate, DayOfWeek.Monday);
| >
| > Alternatively you could use a switch statement if the first day of
week
is
| > fixed...
| >
| > Hope this helps
| > Jay
| >
| >
| > | > | Thank you Nicholas.
| > |
| > | Is there any way to do that in C#?
| > |
| > | Regards,L
| > |
| > | "Nicholas Paldino [.NET/C# MVP]" <
[email protected]>
wrote
| > in
| > | message | > | > L,
| > | >
| > | > You can still call this. Set a reference to
| > Microsoft.VisualBasic.dll,
| > | > and then call the static DatePart method on the DateAndTime class
in
| > the
| > | > Microsoft.VisualBasic namespace.
| > | >
| > | > Hope this helps.
| > | >
| > | >
| > | > --
| > | > - Nicholas Paldino [.NET/C# MVP]
| > | > - (e-mail address removed)
| > | >
| > | > | > | >> dateTime sellDate;
| > | >> int16 dayOfWeek;
| > | >>
| > | >> dayOfWeek=sellDate.DayOfWeek
| > | >>
| > | >> I would like to set that monday is the first day of a week and
not
| > | >> sunday.
| > | >> Any idea?
| > | >>
| > | >> In VB there is a function, where you declare which day should be
the
| > | >> first:
| > | >>
| > | >> DatePart(DateInterval.Weekday, sellDate, vbMonday)
| > | >>
| > | >> Regards,
| > | >> L
| > | >>
| > | >>
| > | >
| > | >
| > |
| > |
| >
| >
|
|