Results 1 to 4 of 4

Thread: Add time and date from two dtp DateTimePickers [RESOLVED]

  1. #1

    Thread Starter
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Resolved Add time and date from two dtp DateTimePickers [RESOLVED]

    I have two dtps on a form, one is set up for a date, the other is set up as "HH:mm" for a time. I need to combine the two values into a single string for insertion into a database.

    What is the easiest way of doing this?

    My problem is that I'm getting the time and date from the second dtp when I only want the time.
    Last edited by trisuglow; Mar 23rd, 2005 at 05:27 AM.
    This world is not my home. I'm just passing through.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Add time and date from two dtp DateTimePickers

    Use the Format function to format each dtp's value. Then concatinate them together.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Lively Member sinchan's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    106

    Thumbs up Re: Add time and date from two dtp DateTimePickers

    VB Code:
    1. [FONT=Courier New]
    2. Private Sub Form_Load()
    3.     Dim mDate As Date
    4.     mDate = CDate(Format(DTPicker1, "dd/mm/yy") & Format(DTPicker2, " hh:mm"))
    5.     MsgBox mDate
    6. End Sub[/FONT]

    DTPIcker1 has date value and DTPicker2 has time value and in the combination of the both, you will get the result in mDate variable which can be inserted in database.
    i love VB more than BV(means wife in our language)

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Add time and date from two dtp DateTimePickers

    Another option. Set the Time of the first date picker from the second beforehand.

    VB Code:
    1. dtp1.Hour = dtp2.Hour
    2. dtp1.Minute = dtp2.Minute
    3. dtp1.Second = dtp2.Second
    4.  
    5. msgbox Format$(dtp1.Value,"dd-MMM-yyyy hh:mm:ss")

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