473,505 Members | 16,800 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calculating date time

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
5 1757
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

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
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
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
whoops - read it too fast. disregard my response.
Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
9425
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
5
2284
by: Gord | last post by:
Many scripts and calendars call client side system time in order to make presentations. However, the client's time may be improperly set, if set at all, and/or the relevant time may be from...
3
3274
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when...
25
4994
by: Umesh | last post by:
i want to calculate the time required to execute a program. Also i want to calcute the time remaining for the execution of the program. how can i do that? pl mention some good websites for...
6
8995
by: krishnakant Mane | last post by:
hello, I am strangely confused with a date calculation problem. the point is that I want to calculate difference in two dates in days. there are two aspects to this problem. firstly, I can't get...
1
1964
by: rodneyeid | last post by:
Hi, I have an attendance machine which saves records in an Access Database in the following format : UserID DATE/TIME Checktype where if checktype is 0 then its check in and if it is 1 then it...
4
2409
by: Brian | last post by:
I have a 2000/2002 Access db that I use to collect and store my exercisetime using a form to enter. I wanted to see a summary of the total timefor each exercise so I have a subform that does this....
4
2099
by: Nathan Sokalski | last post by:
When determining whether a String can be converted to a DateTime, you can use the IsDate() method. However, I would also like to know whether the string is a date, a time, or both a date and a...
4
32941
by: ahmurad | last post by:
Dear Brothers, I am struggling the following four Date-Time type values which were inputted into MYSQL database in different tables. As MYSQL Default Time Format: YYYY-MM-DD HH:MM:SS, So I used...
0
7307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7021
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.