[RESOLVED] Display Date and Time-VBForums
Results 1 to 18 of 18

Thread: [RESOLVED] Display Date and Time

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2015
    Location
    ANTANANARIVO
    Posts
    332

    Resolved [RESOLVED] Display Date and Time

    Hello VBForums
    Hello every one
    Please Gentelmans ..
    If you can help me to resolve my problem ..
    I want to display in TextBox1 (my username and date and time) like this : MADA09112017192556
    I tried with this code but I have not arrived
    Code:
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            TextBox1.Text = "MADA" + Format(Now, "ddmmyy") + Format(Now, "hhmmss")
        End Sub
    End Class
    Thank you in advance for help
    Cordially
    MADA

  2. #2
    Addicted Member
    Join Date
    Sep 2017
    Posts
    137

    Re: Display Date and Time

    TextBox1.Text = "MADA" & Now.ToString("ddmmyy") & Now.ToString("hhmmss")

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2015
    Location
    ANTANANARIVO
    Posts
    332

    Re: Display Date and Time

    Hiii kpmc
    Thank you very very much for help
    But i have in TextBox1 like this : MADA094117074150 .. Date 094117 .....41 !!??
    Thank you
    MADA

  4. #4
    Addicted Member
    Join Date
    Sep 2017
    Posts
    137

    Re: Display Date and Time

    I would advise that you review this
    https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2015
    Location
    ANTANANARIVO
    Posts
    332

    Re: Display Date and Time

    Thank you kpmc
    I am very beginner in this domain
    I did not understand anything in this link
    Cordially ....
    How to display 11 instead of 41
    MADA09112017201933
    MADA

  6. #6
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,025

    Re: Display Date and Time

    Well, if you're using a relatively recent VB you should just use DateTime format strings.

    The Format() function is for school teachers and other people who don't know 1997 ended a little while ago. It's been replaced by String.Format() or parameters to the .ToString() method in .NET, and more generally the concept is called "composite formatting". You should only use Format() these days when trying to write tutorials with the motive of "sabotaging future VB programmers".

    In modern VB we might write:
    Code:
    TextBox1.Text = DateTime.Now.Format("MADAddMMyyyyhhmmss")
    You could also:
    Code:
    TextBox1.Text = $"{DateTime.Now:\MADAddMMyyyyhhmmss}"
    In some flavors of VB, where we believe 2015 ended a short time ago. (The people who don't believe this are sort of lucky: 2017 is a very bad year.)
    Nothing I post is production-ready. It is provided as-is, use it at your own risk.

  7. #7
    Addicted Member
    Join Date
    Sep 2017
    Posts
    137

    Re: Display Date and Time

    How to display 11 instead of 41
    MADA09112017201933
    Perhaps there is a communication breakdown here. You have a value in the textbox that youre trying to format? "41" is what, the minute? /puzzled

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2015
    Location
    ANTANANARIVO
    Posts
    332

    Re: Display Date and Time

    Thank you Sitten for help and explanation
    I am really disappointed .. in VB6 we will do it in 2 seconds
    Regrettably
    The two codes do not work
    Name:  1.jpg
Views: 39
Size:  22.4 KB
    Cordially
    MADA

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    39,375

    Re: Display Date and Time

    It seems Sitten made a rare mistake, try this:
    Code:
    TextBox1.Text = DateTime.Now.ToString("MADAddMMyyyyhhmmss")

  10. #10
    Addicted Member
    Join Date
    Sep 2017
    Posts
    137

    Re: Display Date and Time

    I am going to guess and say you want this

    Code:
    TextBox1.Text = "MADA" & Now.ToString("ddMyy") & Now.ToString("hhmmss")

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2015
    Location
    ANTANANARIVO
    Posts
    332

    Re: Display Date and Time

    Quote Originally Posted by si_the_geek View Post
    It seems Sitten made a rare mistake, try this:
    Code:
    TextBox1.Text = DateTime.Now.ToString("MADAddMMyyyyhhmmss")
    Thank you si_the_geek
    Very happy to meet you again in this subject
    It works but just a small mistake
    The M ( Mada) does not exist and there is a place 11
    11ADA09112017085041
    Cordially
    MADA

  12. #12
    Addicted Member
    Join Date
    Sep 2017
    Posts
    137

    Re: Display Date and Time

    The M ( Mada) does not exist and there is a place 11
    11ADA09112017085041
    its cuz it think M = month

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2015
    Location
    ANTANANARIVO
    Posts
    332

    Re: Display Date and Time

    Quote Originally Posted by kpmc View Post
    its cuz it think M = month
    Thank you very much
    But the month ... is in this part ( 09112017 )
    Cordially
    MADA

  14. #14
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,188

    Re: Display Date and Time

    Mada - then think about it... seriously... just think about it for a second... if "M" is giving you the month number, and that's not what you want... then .... oh screw it...

    TextBox1.Text = "MADA" & DateTime.Now.ToString("ddMMyyyyhhmmss")


    there... done...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2015
    Location
    ANTANANARIVO
    Posts
    332

    Re: Display Date and Time

    Hiii techgnome
    Now it works very well
    That's exactly what I want to see and have
    Thank you for your impeccable code
    Thank you master
    Perfectly resolved
    Cordially
    MADA

  16. #16
    Addicted Member
    Join Date
    Sep 2017
    Posts
    137

    Re: [RESOLVED] Display Date and Time

    tech, i love you man, you just made my week

  17. #17
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,025

    Re: [RESOLVED] Display Date and Time

    There were some mistakes when I went to edit the post.

    But if you look at my two examples, there's a tiny difference.

    Sometimes one character makes all the difference in the world, which is why it's important to read closely.
    Nothing I post is production-ready. It is provided as-is, use it at your own risk.

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2015
    Location
    ANTANANARIVO
    Posts
    332

    Re: [RESOLVED] Display Date and Time

    Quote Originally Posted by Sitten Spynne View Post
    There were some mistakes when I went to edit the post.

    But if you look at my two examples, there's a tiny difference.

    Sometimes one character makes all the difference in the world, which is why it's important to read closely.
    Thank you very much Sitten Spynne for your effort
    Cordially
    MADA

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.