473,657 Members | 2,294 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 1763
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.Su btract(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.FromDa ys(17D); // 17 days (D = double modifier)
DateTime now = DateTime.Now;

DateTime start = now.Subtract(sp an);

--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"Carlos" <ch******@yahoo .com> wrote in message news:eF******** ******@TK2MSFTN GP09.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.WriteLi ne(ts.Milliseco nds);
// 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
9436
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 $ Last-Modified: $Date: 2003/10/28 19:48:44 $ Author: A.M. Kuchling <amk@amk.ca> Status: Draft Type: Standards Track
5
2300
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 another time zone. It would be of great value if the time of some central source could be drawn, in the form of a ".js" file, into the script to avoid dependence on the client's date/time.
3
3291
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 the field should only be showing one or the other (date or time). Even on the back end of the database where the column properties are, I have chosen the smallest date/time formats. When the aspx page runs, it shows the date and time (ie:in a...
25
5009
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 learning advanced C.thx.
6
9015
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 a way to convert a string like "1/2/2005" in a genuan date object which is needed for calculation. now once this is done I will create a another date object with today = datetime.datetime.now() and then see the difference between this today and...
1
1972
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 check out I need to calculate number of hours for each userID /day. I.e UserID =1 DATE/Time= 11/12/2007 12:36 P.M CheckType=0 UserID = 1 DATE/Time= 11/12/2007 17:36 P.M CheckType=1 i am counting the day as being from 12:00 am till...
4
2431
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. Only issue is thatwhen I go over 24 hrs I get the infamous summing time issue. It would bereally easy if Access used the Excel :nn format, but it doesn't. Whycan't this be used in Access, Microsoft?????????????????..anyway Idigress. I have two...
4
2114
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 time. Is there any simple way to do this without using manual pattern matching? Thanks. -- Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
4
32948
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 the MYSQL Tables DateTime Type as Text. Time-formet 1. 04:02:27 16/01/2009 Time-formet 2. 16/01/2009 13:53:19 Time-formet 3. 00901E+13 Time-formet 4. Wed Jan 14 00:09:09 BDT 2009
0
8407
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8319
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8837
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7347
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5638
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.