Solved

Date Subtraction

Posted on 2000-02-22
8
504 Views
Last Modified: 2011-09-20
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
Thanks
Dave Steers
0
Comment
Question by:dsteers
  • 4
  • 3
8 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 50 total points
ID: 2548740
DateDiff do it very easily.

msgbox datediff("d","march 2 2000", "april 4 2000")
0
 

Expert Comment

by:pinshah
ID: 2557165
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
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 2558573
pinshah,

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

dsteers,

Is it working now?
0
 

Author Comment

by:dsteers
ID: 2560192
Think so,
I'll try it out
Thanks
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:dsteers
ID: 2563685
Why Copy emoreau's Comment and post it as an answer.
Sorry
0
 

Author Comment

by:dsteers
ID: 2563693
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.

Thanks

Dave Steers
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 2564861
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
0
 

Author Comment

by:dsteers
ID: 2571108
I'll Try it out.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now