time and date

  • Thread starter Thread starter sara
  • Start date Start date
S

sara

Hi,
Why the endDate is the same, "2/1/2009 12:00:00 AM", for the both
assignment though the second one should be greater than the first one
by 30 dats?

DateTime startDate = new DateTime(1981, 1, 1);
endDate = startDate.AddDays(10228);
endDate = startDate.AddDays(10258);


Thanks a lot
Sara.
 
sara laid this down on his screen :
Hi,
Why the endDate is the same, "2/1/2009 12:00:00 AM", for the both
assignment though the second one should be greater than the first one
by 30 dats?

DateTime startDate = new DateTime(1981, 1, 1);
endDate = startDate.AddDays(10228);
endDate = startDate.AddDays(10258);


Thanks a lot
Sara.

You must have a mistake somewhere else. When I run this:

DateTime startDate = new DateTime(1981, 1, 1);
DateTime endDate1 = startDate.AddDays(10228);
DateTime endDate2 = startDate.AddDays(10258);

Console.WriteLine(endDate1.ToString("dd-MMM-yyyy"));
Console.WriteLine(endDate2.ToString("dd-MMM-yyyy"));

I get
02-jan-2009
01-feb-2009


Hans Kesting
 
Are you sure it's not a date formatting issue?

The first line returns 2 Jan 2009 and the second line returns 1 Feb 2009
but, depending on your locale and/or culture settings, they might both be
displayed as 2/1/2009 or 1/2/2009...

Of course, the second line updates the endDate variable. Are you sure you
don't actually need two variables, e.g.

DateTime startDate = new DateTime(1981, 1, 1);
DateTime endDate1 = startDate.AddDays(10228);
DateTime endDate2 = startDate.AddDays(10258);

Sorry it was my mistake.
 
Back
Top