albert albert

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

Answers (2)