TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
albert albert
NA
524
0
Datetime without Time
May 16 2012 6:47 AM
Hi everybody,
I have this:
[code]
var jan1 = (new DateTime(DateTime.Today.Year, 1, 1)).ToShortTimeString();
//beware different cultures, see other answers
var startOfFirstWeek = jan1.AddDays(1 - (int)(jan1.DayOfWeek));
var weeks =
Enumerable
.Range(0, 52)
.Select(i => new
{
weekStart = startOfFirstWeek.AddDays(i * 7)
})
.TakeWhile(x => x.weekStart.Year <= jan1.Year)//Week will nog begin by first of January
.Select(x => new
{
x.weekStart,
weekFinish = x.weekStart.AddDays(6)
})
.SkipWhile(x => x.weekFinish < jan1.AddDays(1))//Week will end by 31 of December
.Select((x, i) => new
{
x.weekStart,
x.weekFinish,
weekNum = i + 1
});
foreach (var week in weeks)
{
Console.WriteLine(week.ToString());
}
[/code]
But I only want to have the date without time.
THX
Reply
Answers (
2
)
Grid view insert, update and delete
getting week dates of dropdownlist of weeks