473,395 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

difference between 2 dates

I would like to know how I can calculate the diference in time between 2
dates. I would input a date (before the current date) and the code would
calulate how many: weeks, days, hours, minutes and secondes there is between
the given date and the current date.

thanx in advance!

Lovens
Nov 21 '05 #1
3 1154
This should answer your question:

http://msdn.microsoft.com/library/de...sDateTopic.asp

Richard Rosenheim
"weche" <fw****@videotron.ca> wrote in message
news:Xw********************@weber.videotron.net...
I would like to know how I can calculate the diference in time between 2
dates. I would input a date (before the current date) and the code would
calulate how many: weeks, days, hours, minutes and secondes there is between the given date and the current date.

thanx in advance!

Lovens

Nov 21 '05 #2
Lovens,

For your question is the timespan structure.

http://msdn.microsoft.com/library/de...classtopic.asp

And before you try to do difficult things, look at the properties and
methods from that.

As well can you look at the date and time methods in the
Microsoft.VisualBasic namespace about dates, they can be very helpfull and
although a lot of the functions in this namespace are in another way in the
standard framework, are here some which are not.

http://msdn.microsoft.com/library/de...rykeywords.asp

I hope this helps,

Cor
Nov 21 '05 #3
"weche" <fw****@videotron.ca> schrieb:
I would like to know how I can calculate the diference in time between 2
dates. I would input a date (before the current date) and the code would
calulate how many: weeks, days, hours, minutes and secondes there is
between
the given date and the current date.


\\\
Dim d1 As Date = Now
Dim d2 As Date = #4/22/1989#
MsgBox(CStr(Math.Round(d1.Subtract(d2).TotalSecond s, 0)))
MsgBox(CStr(DateDiff(DateInterval.Second, d2, d1)))
///

'DateTime.Subtract' will return a 'TimeSpan'. This structure provides
properties like 'Days', 'Minutes', 'Seconds', ...

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4

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

Similar topics

26
by: Frank | last post by:
For my website i would like to display the age of my son in years, months, days and hours. For now i manage to get a result for totals. Like the total number of days. This is the beginning: ...
6
by: Ashish Sheth | last post by:
Hi All, In C#, How can I get the difference between two dates in number of months? I tried to use the Substract method of the DateTime class and it is giving me the difference in TimeSpan,From...
4
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow...
4
by: Yotam | last post by:
Hi, I need some help with JS. I will be grateful, if you can help me out. I have two date fields (check in, check out) and "number of days" field. I want the script to calculate automatically...
2
by: Blackmore | last post by:
I am trying to use javascript to calculate the difference between two form inputted dates and return the result to another form object. When I load up the page with the function on my web browser...
8
by: Claudia Fong | last post by:
Hi, In VB we have DateDiff to calculate the days difference between 2 dates, I was wondering if we have something like that in C#? I want to calculate for example the days difference...
1
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hi, misters which the best method for get the difference (in days) of two dates. The hour (hh:mm) don't mind, would be 00:00 for all dates. 1.) fechaUno.Substract(fechaDos).Days 2.)
3
by: prashantkuppa | last post by:
hi, iam struggling with difference between two dates of format type dd/mm/yyyy i need difference between two dates olddate(dd/mm/yyyy) - newdate(dd/mm/yyyy) and this should be in java script...
4
by: sniipe | last post by:
Hi! I am new in Python, so I count for your help. I need to get difference in months between two dates. How to do it in python? I am substracting two dates, for example date1 - date2 and I got...
4
by: lenygold via DBMonster.com | last post by:
I found this example in MYSQL: create table events ( id integer not null primary key , datetime_start datetime not null , datetime_end datetime not null ); insert into events values ( 1,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...

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.