By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,659 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,659 IT Pros & Developers. It's quick & easy.

calculating date time

P: n/a
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.
Nov 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Carlos wrote:
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));

--
Rob Schieber
Nov 17 '05 #2

P: n/a

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 wrote:
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.

Nov 17 '05 #3

P: n/a
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);

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"Carlos" <ch******@yahoo.com> wrote in message news:eF**************@TK2MSFTNGP09.phx.gbl...
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.

Nov 17 '05 #4

P: n/a
Carlos wrote:
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.

--
jeremiah();
Nov 17 '05 #5

P: n/a
whoops - read it too fast. disregard my response.
Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.