How to get addition between two dates (dd/mm/yy)

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 2620 Views - Last Post: 16 December 2011 - 11:21 PM Rate Topic: -----

#1 MCBS  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 22-August 11

How to get addition between two dates (dd/mm/yy)

Posted 26 November 2011 - 05:52 AM

Hello everyone
i tried one thing to get the addition between two date
i creat three texts. text1,text2 and text3
and one Command button
i wrote the code in button1


text3=val(text1)+ val(text2)


then when i wrote in text1, date like this format dd/mm/yy and same thig with text2 dd/mm/yy
i got just the addition around day
for example
1/1/2011
25/1/2011
i got just 26!!

but what i would to get the additon to whole date (dd/mm/yy +dd/mm/yy =dd/mm/yy )

Is This A Good Question/Topic? 0
  • +

Replies To: How to get addition between two dates (dd/mm/yy)

#2 MCBS  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 22-August 11

Re: How to get addition between two dates (dd/mm/yy)

Posted 26 November 2011 - 07:52 AM

but what if i would to get the additon to whole date (dd/mm/yy +dd/mm/yy =dd/mm/yy )
Was This Post Helpful? 0
  • +
  • -

#3 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: How to get addition between two dates (dd/mm/yy)

Posted 26 November 2011 - 09:23 AM

Ummm ok, That wont work, but good attempt...

Although i havent used it i believe that the DateDiff() function is what your looking for, it compaires two dates and returns a value...

Im sure that you could google it or see if you could find it with in the forums here...

Best of luck

Jesse Fender
Was This Post Helpful? 0
  • +
  • -

#4 Raaj71  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 56
  • Joined: 21-October 11

Re: How to get addition between two dates (dd/mm/yy)

Posted 27 November 2011 - 08:29 PM

What are you trying to get by adding two dates ?

Where you plan to use it ? If you are trying to get some date in future, you can develop a logic to get future date but adding dates just like numeric wont produce any result.
Was This Post Helpful? 0
  • +
  • -

#5 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 179
  • Posts: 1,599
  • Joined: 17-April 07

Re: How to get addition between two dates (dd/mm/yy)

Posted 29 November 2011 - 02:52 AM

i follow Raaj71 here,
OK as per your need what it the desired output for your two Dates
Was This Post Helpful? 0
  • +
  • -

#6 MCBS  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 22-August 11

Re: How to get addition between two dates (dd/mm/yy)

Posted 29 November 2011 - 04:15 PM

sorry guys i would some thing different of what i wrote before
first i would this program for my brother . He wants it for his job

he would to write date first like 1/2/2011 then will write Number any numbers for example 23
Then will get the addition
1/2/2011
23
= 24/2/2011
how can i do it ?
Was This Post Helpful? 0
  • +
  • -

#7 guyfromri  Icon User is offline

  • D.I.C Addict

Reputation: 46
  • View blog
  • Posts: 805
  • Joined: 16-September 09

Re: How to get addition between two dates (dd/mm/yy)

Posted 30 November 2011 - 01:45 AM

This should help -- this piece of code should help but you'll have to add in the pieces for checking diff months and amount of allowed days

'''Typed here -- may be a little buggy
Sub Test()

Dim strDate As String
Dim NumToAdd As Integer
Dim IntDate As Integer
Dim NewDatePiece As Integer
Dim NewDate As String

strDate = "1/2/2011"
NumToAdd = 23

IntDate = Left(strDate, InStr(1, strDate, "/") - 1)
NewDatePiece = Int(IntDate) + NumToAdd

NewDate = NewDatePiece & Mid(strDate, InStr(1, strDate, "/"))

Debug.Print NewDate

End Sub



That should give the exact result you listed above :)

This post has been edited by guyfromri: 30 November 2011 - 01:57 AM

Was This Post Helpful? 0
  • +
  • -

#8 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,755
  • Joined: 26-March 09

Re: How to get addition between two dates (dd/mm/yy)

Posted 30 November 2011 - 02:20 AM

You can use something like:

MsgBox CStr(CDate(strDate) + CInt(strNumberOfDays))

This post has been edited by maj3091: 30 November 2011 - 02:21 AM

Was This Post Helpful? 0
  • +
  • -

#9 MCBS  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 22-August 11

Re: How to get addition between two dates (dd/mm/yy)

Posted 30 November 2011 - 02:21 AM

View Postguyfromri, on 30 November 2011 - 01:45 AM, said:

This should help -- this piece of code should help but you'll have to add in the pieces for checking diff months and amount of allowed days

'''Typed here -- may be a little buggy
Sub Test()

Dim strDate As String
Dim NumToAdd As Integer
Dim IntDate As Integer
Dim NewDatePiece As Integer
Dim NewDate As String

strDate = "1/2/2011"
NumToAdd = 23

IntDate = Left(strDate, InStr(1, strDate, "/") - 1)
NewDatePiece = Int(IntDate) + NumToAdd

NewDate = NewDatePiece & Mid(strDate, InStr(1, strDate, "/"))

Debug.Print NewDate

End Sub



That should give the exact result you listed above :)


Thank alot guyfromri
i tried to write ur code but i think i put it i wrong place
i attached picture of program (HOPE YOU look at it)
at Received date ( i would write date any date d/m/yyyy )
and at No of date (will write number ,the idea of numbers as days. in brief, when i received some request from my custamer i will write the date of receving request, then i will tell my custamer i will finish this request after 10 day from recieving date.so when i click on Get compilation i would get the addition on text3)

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#10 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 179
  • Posts: 1,599
  • Joined: 17-April 07

Re: How to get addition between two dates (dd/mm/yy)

Posted 01 December 2011 - 03:49 AM

please show your code we will rectify the bug
Was This Post Helpful? 0
  • +
  • -

#11 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 571
  • View blog
  • Posts: 2,979
  • Joined: 19-May 09

Re: How to get addition between two dates (dd/mm/yy)

Posted 09 December 2011 - 07:26 AM

You'll want to look into the DateDiff function, if I understand your problem correctly.
Was This Post Helpful? 0
  • +
  • -

#12 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: How to get addition between two dates (dd/mm/yy)

Posted 09 December 2011 - 02:09 PM

View PostBobRodes, on 09 December 2011 - 06:26 AM, said:

You'll want to look into the DateDiff function, if I understand your problem correctly.



YAY some one agreed with me!
Was This Post Helpful? 0
  • +
  • -

#13 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,755
  • Joined: 26-March 09

Re: How to get addition between two dates (dd/mm/yy)

Posted 10 December 2011 - 03:32 AM

View PostMCBS, on 29 November 2011 - 04:15 PM, said:

he would to write date first like 1/2/2011 then will write Number any numbers for example 23
Then will get the addition
1/2/2011
23
= 24/2/2011
how can i do it ?


Based on the request above, I'm not sure DateDiff (I'll wait for Bob to prove me wrong as usual. ;-) ) will do what's required, which is why I suggested something like below to do it:

MsgBox CStr(CDate(strDate) + CInt(strNumberOfDays))


Was This Post Helpful? 0
  • +
  • -

#14 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 571
  • View blog
  • Posts: 2,979
  • Joined: 19-May 09

Re: How to get addition between two dates (dd/mm/yy)

Posted 13 December 2011 - 09:34 AM

Ok, I was only reading the first one, not the clarification. Try using the DateAdd function: Text3.Text = DateAdd(Text1.Text, Text2.Text). Have a look here.
Was This Post Helpful? 2
  • +
  • -

#15 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,755
  • Joined: 26-March 09

Re: How to get addition between two dates (dd/mm/yy)

Posted 13 December 2011 - 10:26 AM

View PostBobRodes, on 13 December 2011 - 09:34 AM, said:

Ok, I was only reading the first one, not the clarification. Try using the DateAdd function: Text3.Text = DateAdd(Text1.Text, Text2.Text). Have a look here.


That's why I like your posts...I'm always learning something new. I didn't even know VB had a DateAdd function!
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2