| Author: Tausif L Nakhuda 04 Nov 2008 | Member Level: Silver | Rating:    Points: 6 |
Hi Badal, You can use the substract method of the DateTime class to get the difference between the 2 dates.
e.g. Considering 2 dateTime variables , the difference can be calculated as shown in the code below.
DateTime d1 = new DateTime(8,11,5); DateTime d2 = new DateTime(8,11,4); MessageBox.Show( d1.Subtract(d2).TotalDays.ToString());
Hope this helps. Regards. T.L.N
|
| Author: archana 04 Nov 2008 | Member Level: Gold | Rating:    Points: 6 |
hi
you can use any of the followiing (1) DateTime firstdate =Convert.ToDateTime("03/08/2006"); DateTime secondate =Convert.ToDateTime("07/08/2007");
TimeSpan TS = secondate - firstdate;
Response.Write(TS.TotalDays);
(2) Dim d2 As DateTime d1 = Convert.ToDateTime("03/08/2006") d2 = DateTime.Now Dim s As String s = FormatNumber((DateDiff(DateInterval.Day, d1, d2))) Response.Write(s)
(3) select DATEDIFF(dd,Col_Name,getdate()) from table_name
|
| Author: Rajaraman 04 Nov 2008 | Member Level: Diamond | Rating:    Points: 6 |
DateTime.Subtract method returns a TimeSpan object, which has properties such as Days, Hours, Minutes and so on to get the difference in specific measurements.
Please find the code snippet for more info.
// Start date DateTime startDate = new DateTime(2005, 2, 1, 3, 4, 12, 56); // End date DateTime endDate = new DateTime(2005, 12, 12, 4, 30, 45, 12); // Time span TimeSpan diffDate = endDate.Subtract ( startDate ); // Spit it out Console.WriteLine( "Time Difference: "); Console.WriteLine(diffDate.Days.ToString() + " Days"); Console.WriteLine(diffDate.Hours.ToString() + " Hours" ); Console.WriteLine(diffDate.Minutes.ToString() + " Minutes"); Console.WriteLine(diffDate.Seconds.ToString() + " Seconds "); Console.WriteLine(diffDate.Milliseconds.ToString() + " Milliseconds ");
Let me know if you have any questions.
|
| Author: Anil Kumar Pandey 04 Nov 2008 | Member Level: Diamond | Rating:  Points: 2 |
hi,
u can use the inbuilt datetime function for doing the task u can use the following method to get the date difference
DateTime dt; DateTime dt2; dt.Subtract(dt2);
Regards Anil Pandey
Thanks & Regards Anil Kumar Pandey
|
| Author: Gaurav Agrawal 04 Nov 2008 | Member Level: Diamond | Rating:  Points: 2 |
DateTime dt1 = new DateTime(); DateTime dt2 = new DateTime(); TimeSpan ts = dt2.Subtract(dt1);
GA
Thanks & Regards,
Gaurav Agrawal Sr.Software Engineer gaur1982@yahoo.com 09829373514
|