A simple program to calculate number of days between two dates


I need a simple Visual Basic coding for developing a days between two dates calculator. I am new to visual basic and need further help.
The program should contain Two text boxes
text1.text for Initial Date
text2.text for End date
And the no. of days between these dates should be displayed in a label.

Please help me overcoming this problem by posting a suitable source code for this VB 6 project.
Any help would be highly appreciated.
Thanx in advance....
Tarpit Sahu

If you enjoyed this post, subscribe for updates (it's free)

Thank You very muck for your

Thank You very muck for your kind help

Date Difference

Private Sub cmdCalculate_Click()
lblYears.Caption = ""
lblMonths.Caption = ""
lblDays.Caption = ""
lblQuarter.Caption = ""
lblCalenderWeeks.Caption = ""
lblWeeks.Caption = ""
lblHours.Caption = ""
lblMinutes.Caption = ""
lblSeconds.Caption = ""

lblYears.Caption = DateDiff("YYYY", dtpStartDate.Value, dtpEndDate.Value)
lblMonths.Caption = DateDiff("M", dtpStartDate.Value, dtpEndDate.Value)
lblDays.Caption = DateDiff("D", dtpStartDate.Value, dtpEndDate.Value)
lblQuarter.Caption = DateDiff("Q", dtpStartDate.Value, dtpEndDate.Value)
lblCalenderWeeks.Caption = DateDiff("WW", dtpStartDate.Value, dtpEndDate.Value)
lblWeeks.Caption = DateDiff("W", dtpStartDate.Value, dtpEndDate.Value)
lblHours.Caption = DateDiff("H", dtpStartDate.Value, dtpEndDate.Value)
lblMinutes.Caption = DateDiff("N", dtpStartDate.Value, dtpEndDate.Value)
lblSeconds.Caption = DateDiff("S", dtpStartDate.Value, dtpEndDate.Value)
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 27 Then
End
End If
End Sub

Private Sub Form_Load()
dtpStartDate.Value = Date
dtpEndDate.Value = Date
End Sub

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.