Click here to Skip to main content
15,667,436 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friends,
how to count between two date ?
please help me

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
    class Program
        static void Main(string[] args)
            DateTime dtA = new DateTime(2012, 12, 25);
            DateTime dtB = new DateTime(2012, 12, 26);

            Console.WriteLine("Day Difference : " + Math.Abs(DateTime.Compare(dtA, dtB)));
Share this answer
Dim i As Integer
Dim Date1 As Date
Dim Date2 As Date
Date1 = CDate("1 Jan 2012")
Date2 = Now.Date
i = DateDiff(DateInterval.Day, Date1, Date2)
Msgbox("Days Difference: " & i)
i = DateDiff(DateInterval.Month, Date1, Date2)
Msgbox("Month Difference: " & i)
' Similarly You can Calculate Difference of Weeks, Years, Hours, Secs, Minutes 
' between two Dates...
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900