calculating date time

  • Thread starter Thread starter Carlos
  • Start date Start date
C

Carlos

Hi all,

I have used the datetime class, but I just came up with a situation
that need to have some advise. If I now how much time have passed,
can I know the original date?. Lets say that I know that have passed
2 weeks and 3 days after any given event. How can I know the original
date of the event?

Thanks in advance.


Carlos.
 
If you know that the difference between two dates is 17 days, then, so
long as you know one of the days, you can find the other.

If Day2 - Day1 = 17 Days, then Day1 + 17 = Day 2.

But, if all you known is 17 days, but you don't know when that 17 days
stopped, or started, then I don't see how you can get any more
information than that.

--Brian
 
Carlos said:
Hi all,

I have used the datetime class, but I just came up with a situation
that need to have some advise. If I now how much time have passed,
can I know the original date?. Lets say that I know that have passed
2 weeks and 3 days after any given event. How can I know the original
date of the event?

Thanks in advance.


Carlos.

Hi Carlos,

Use the timespan class.

2 weeks, 3 days = 17 days,

DateTime origDate = DateTime.Now.Subtract(new TimeSpan(17, 0,0,0,0));
 
You need some frame of reference first. If 2 weeks and 3 days have passed until NOW (or a specified date), then you can get the
original date.

TimeSpan span = TimeSpan.FromDays(17D); // 17 days (D = double modifier)
DateTime now = DateTime.Now;

DateTime start = now.Subtract(span);
 
Carlos said:
Hi all,

I have used the datetime class, but I just came up with a situation
that need to have some advise. If I now how much time have passed,
can I know the original date?. Lets say that I know that have passed
2 weeks and 3 days after any given event. How can I know the original
date of the event?

Thanks in advance.
Carlos.

DateTime then = DateTime.Now;

.... // stuff happens here.

DateTime now = DateTime.Now;

TimeSpan ts = now - then;

Console.WriteLine(ts.Milliseconds);
// or ts.Seconds, or ts.Minutes, or whatever.
 
Back
Top