J. Petersen J. Petersen - 1 year ago 78
C# Question

offset datetime with each other - Must tell the number of days in total

I must have built up such that I have a datetime which gets added antale day as it should go forward. and then I have time as it should set off in relation to 04/10/16 to 10/09/16

I do not care about the time which is in datetime. It should not I use for anything. What I need out of this is exactly how many days there are from that time.

Datetime dateString = "4/10/2016 8:30:52" //I pretend that it comes from the database, it was more in terms of see what come there.
DateTime dt = DateTime.Now.AddDays(5);

What I need out of this is that it tell me how many days there are in between the two datetime as I entered.

Answer Source

DateTime objects support basic operators and will return TimeSpan objects.

DateTime DateTimeB = DateTime.Now.AddDays(5);
DateTime DateTimeA = DateTime.Now;
TimeSpan difference = DateTimeA - DateTimeB;

... you can then use the TotalDays property of the timeSpan. ...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download