Click here to Skip to main content
13,591,670 members
Rate this:
Please Sign up or sign in to vote.
See more:
hi friends,
how to count between two date ?
please help me
Posted 25-Dec-12 20:20pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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)));
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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...

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web02-2016 | 2.8.180618.1 | Last Updated 26 Dec 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100