Solved

Date Subtraction

Posted on 2000-02-22
8
508 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 70

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 70

Expert Comment

by:Éric Moreau
ID: 2558573
pinshah,

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

dsteers,

Is it working now?
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:dsteers
ID: 2560192
Think so,
I'll try it out
Thanks
0
 

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 70

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

770 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