|
|
Home » ASP » Article
Calculating Date Differences with DateDiff
|
| Article by: | Art Downey (3/17/2003) |
|
| Summary: | A summary of the various ways of calculating the difference between two dates. |
|
| Viewed: 103803 times |
Rating (23 votes): |
|
3.8 out of 5 |
|
|
|
Calculating Date Differences with DateDiff
To calculate the number of months between today and another date, use
Date here, of course, is the vbscript date function which returns todays date.
The "m" specifies month. Here are a complete list of the other options available.
| Setting |
Description |
| yyyy |
Year |
| q |
Quarter |
| m |
Month |
| y |
Day of year |
| d |
Day |
| w |
Weekday |
| ww |
Week of year |
| h |
Hour |
| n |
Minute |
| s |
Second |
|
|
View highlighted Comments
User Comments on 'Calculating Date Differences with DateDiff'
|
Posted by :
Archive Import (Joel Omeike) at 10:50 on Monday, May 19, 2003
|
Thanks a lot for this article.
I've been building an extensive online payment platform and had been having problems with the transaction history. your article just sorted this out. cheers,
joel
jomeike@mail.com
| |
|
|
Posted by :
Archive Import (Tina Baker) at 11:32 on Tuesday, September 16, 2003
|
I found your article of interest, there is only one problem that I need to address rather than going in to lengthy code.
DiffADate = "Years old = " & DateDiff("yyyy", 24/09/1991, [16/09/2003])
[assume this is the now system Date]
In theory this should return "Years Old = 11" it returns 12, please advise
| |
Posted by :
jennuhw at 15:14 on Tuesday, September 30, 2003
|
You are finding the difference between the years which is 12.
| |
Posted by :
Opels at 04:02 on Monday, June 06, 2005
|
Hi,
I am using C#. I would like to calculate the difference between 2 dates and the result is expected to be in No. of Days. Refer to the below example
DateTime dt1 = dr[REC_DATE_COL]; //01/07/2005
DateTime dt2 = dr[DUE_DATE_COL]; //05/07/2005
TimeSpan ts1 = dt1 - dt2;
Messagebox.Show(ts1.Days.ToString()); //Result should be 4 Days
The result shown above in the form of messagebox is returning the result as 120.
Can anyone suggest anything. I'll greatly appreciate it.
Thanks in advance.
Regards.
| |
Posted by :
murali_507 at 06:17 on Wednesday, August 10, 2005
|
Hi opels,
U try this way. The code is in C#
For Example
DateTime dt1= new DateTime(2005,7,1); //01/07/2005
DateTime dt2= new DateTime(2005,7,5); //05/07/2005
Messagebox.Show(dt2.Subtract(dt1).Days)// the result shows 4 as u would expect
Murali
<Added>
Messagebox.Show(Convert.ToString(dt2.Subtract(dt1).Days))//
| |
Posted by :
plsaiuser at 22:23 on Monday, March 13, 2006
|
Greetings All,
in the following code am using Microsoft.VisualBasic in my C# program. with out using Microsoft.VisualBasic can any one help me to give the complete equvalent code in C#
Microsoft.VisualBasic.FirstDayOfWeek z1 = 0;
DateTime dt1= DateTime.Now;
string strDayName = DateAndTime.WeekdayName(DateAndTime.Weekday(dt1,z1),false,z1).ToString();
Thanks
Tec
| |
Posted by :
aliasunway at 10:28 on Friday, June 02, 2006
|
hai.. i'm trying to do the same thing using C++..
can anyone help me ? i'm juz a beginner.. tried so many things but nothing works..
Pleasssss...
| |
|
To post comments you need to become a member. If you are already a member, please log in .
| |