Results 1 to 6 of 6

Thread: [RESOLVED] VB6- DateAdd?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2021
    Posts
    84

    Resolved [RESOLVED] VB6- DateAdd?

    I haven't planned for a while. I have lost elasticity

    My purpose:
    Input a dateinput.text in DDMMJJJJ format
    input of a number of days input.text
    output in Outputdate one Date with - days with the number of days less

    Example
    Dateinput.text=16041982
    Inputdays=289
    Outputdate.text=1.7.1981

  2. #2
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,120

    Re: VB6- DateAdd?

    Code:
        Dim Outputdate As String
        Dim Inputdays As Long
        
        Inputdays = 289
        Outputdate = Format(DateAdd("d", -Inputdays, DateSerial(Right$(Dateinput.Text, 4), Mid$(Dateinput.Text, 3, 2), Left$(Dateinput.Text, 2))), "d.m.yyyy")
        MsgBox Outputdate

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2021
    Posts
    84

    Re: VB6- DateAdd?

    I have 2 textbox
    Inputdays.text=289
    dateinput.text=16041982
    My code
    Code:
    Private Sub Command1_Click()
     Dim inputdays As Long
    Outputdate = Format(DateAdd("d", -inputdays, DateSerial(Right$(dateinput.Text, 4), Mid$(dateinput.Text, 3, 2), Left$(dateinput.Text, 2))), "dd.mm.yyyy")
        MsgBox Outputdate
    End Sub
    Mijn results Outputdate MsgBox is 16041982 ????
    Normally the result should be 1.7.1981
    Last edited by Giorgina; Apr 14th, 2024 at 01:42 AM.

  4. #4
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,120

    Re: VB6- DateAdd?

    Code:
        Dim Outputdate As String
        
        Outputdate = Format(DateAdd("d", -Val(Inputdays.Text), DateSerial(Right$(dateinput.Text, 4), Mid$(dateinput.Text, 3, 2), Left$(dateinput.Text, 2))), "dd.mm.yyyy")
        MsgBox Outputdate

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2021
    Posts
    84

    Re: VB6- DateAdd?

    Thank you, Eduardo.
    It works great. Perfect and solved

  6. #6
    Fanatic Member
    Join Date
    Apr 2021
    Posts
    539

    Re: VB6- DateAdd?

    Quote Originally Posted by Giorgina View Post
    Thank you, Eduardo.
    It works great. Perfect and solved
    Don't forget to mark the thread as resolved, so others know they don't need to look in the post

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width