Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Date Subtraction

Posted on 2000-02-22
8
Medium Priority
?
538 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 200 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

670 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