Results 1 to 5 of 5

Thread: [RESOLVED] Date format question

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    17

    Resolved [RESOLVED] Date format question

    How would I get a label box to just display the current year?

    Thanks
    Aaron

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

    Re: Date format question


    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Label1.Caption = Year(Date)
    5. End Sub
    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

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    17

    Re: Date format question

    That was hard :-p, thanks a lot .

  4. #4
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: [RESOLVED] Date format question

    koolzap351:

    The following code will put the current date into a text box when you click on the text box:

    Private Sub txtDate_Click()
    If txtDate.Text <> CStr(Date) Then
    txtDate.Text = Date
    End If
    End Sub

    If you want to have the date appear in the text box when the form loads, then put this code in the form_load event instead of the txtDate_Click event.


    This code will put the current time into a text box when you click on the text box:

    Private Sub txtTime_Click()
    If txtTime.Text <> CStr(Time) Then
    txtTime.Text = Time
    End If
    End Sub

    Again, if you want the time to appear in the text box when the form is loaded this code need to be in the form_load event.

    This should work.

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

    Re: [RESOLVED] Date format question

    I know. I almost tired myself out for the day.

    Btw, its just called a Label control and not a Label Box.
    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

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