• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 550
  • Last Modified:

Date Subtraction

I wish to enter a day date (e.g. 15) and have it subtracted by
another date that is also entered (in the same format).
It's a normal subtraction except when it goes over months.

eg.      2 March
      4 April
      33 Days      

P.S I'm using VB 6
Dave Steers
  • 4
  • 3
1 Solution
Éric MoreauSenior .Net ConsultantCommented:
DateDiff do it very easily.

msgbox datediff("d","march 2 2000", "april 4 2000")
if u have two dates use
datediff("d","march 2 2000", "april 4 2000")

else if u want to subtract or add days/months etc

use DateAdd
Éric MoreauSenior .Net ConsultantCommented:

You steal my comment! Change it to a comment now.


Is it working now?
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

dsteersAuthor Commented:
Think so,
I'll try it out
dsteersAuthor Commented:
Why Copy emoreau's Comment and post it as an answer.
dsteersAuthor Commented:
Thanks emoreau,
Great help,
also (for another 50 points),
I was wondering if there is some sort of code that would allow subtraction of time,where the times are over two different days.
E.g. 1340 (PM) Wednesday 8 March
     0200 (AM) Thursday 9 March

The Code saying how many days,hours minutes between the two times.


Dave Steers
Éric MoreauSenior .Net ConsultantCommented:
Try this:

Option Explicit

Private Sub Command1_Click()
Dim dtm1 As Date
Dim dtm2 As Date
Dim lngDiff As Long
Dim lngDays As Long
Dim lngHours As Long
Dim lngMinutes As Long

    dtm1 = "2000/03/08 13:40"
    dtm2 = "2000/03/09 2:00"
    'Returns number of minutes
    lngDiff = DateDiff("n", dtm1, dtm2)
    'Extract days
    If lngDiff > (24 * 60) Then
        lngDays = Int(lngDiff / (24 * 60))
        lngDiff = lngDiff - (lngDays * 24 * 60)
    End If
    'Extract Hours
    If lngDiff > 60 Then
        lngHours = Int(lngDiff / 60)
        lngDiff = lngDiff - (lngHours * 60)
    End If
    'Extract Minutes
    lngMinutes = lngDiff
    MsgBox "Difference between dates: " & _
           lngDays & " days, " & _
           lngHours & " hours and " & _
           lngMinutes & " minutes."
End Sub
dsteersAuthor Commented:
I'll Try it out.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now