Convert Now to a string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Laurence

    #1

    Convert Now to a string

    In VS.2005 using VB.NET

    I have tried to make a string

    dim abc as string
    abc = format(now,"mm/dd/yyyy")
    or
    abc format$(now,"mm/dd/yyyy")

    but it doesn't work.

    I get: 28/25/2006

    the day and year are ok, but the month is always wrong,
    the month is something different every time,

    Thanks in Advance,

    Laurence
  • wilson

    #2
    Re: Convert Now to a string

    Use MM for month with leading zero.
    mm is minute with leading zero.

    Laurence wrote:
    In VS.2005 using VB.NET
    >
    I have tried to make a string
    >
    dim abc as string
    abc = format(now,"mm/dd/yyyy")
    or
    abc format$(now,"mm/dd/yyyy")
    >
    but it doesn't work.
    >
    I get: 28/25/2006
    >
    the day and year are ok, but the month is always wrong,
    the month is something different every time,
    >
    Thanks in Advance,
    >
    Laurence


    --

    Comment

    • GhostInAK

      #3
      Re: Convert Now to a string

      Hello Laurence,

      This is covered in the documentation. Press F1.

      -Boo
      In VS.2005 using VB.NET
      >
      I have tried to make a string
      >
      dim abc as string
      abc = format(now,"mm/dd/yyyy")
      or
      abc format$(now,"mm/dd/yyyy")
      but it doesn't work.
      >
      I get: 28/25/2006
      >
      the day and year are ok, but the month is always wrong, the month is
      something different every time,
      >
      Thanks in Advance,
      >
      Laurence
      >

      Comment

      • Greg

        #4
        Re: Convert Now to a string

        "Laurence" <Something@Some thing.comwrote in message
        news:uAYJPuQ4GH A.3644@TK2MSFTN GP03.phx.gbl...
        In VS.2005 using VB.NET
        >
        I have tried to make a string
        >
        dim abc as string
        abc = format(now,"mm/dd/yyyy")
        or
        abc format$(now,"mm/dd/yyyy")
        >
        but it doesn't work.
        >
        I get: 28/25/2006
        >
        the day and year are ok, but the month is always wrong,
        the month is something different every time,
        >
        Thanks in Advance,
        >
        Laurence
        mm = Minute
        MM = Month

        Cheers.


        Comment

        • Cor Ligthert [MVP]

          #5
          Re: Convert Now to a string

          Laurence,

          You are free to use the Format, but did you know that there was the
          overloaded ToString with the DateFormatProvi der

          dim abc as string = now.ToString("d ")

          I am not sure if it is d but that you can lookup on msdn.

          I hope this helps,

          Cor

          "Laurence" <Something@Some thing.comschree f in bericht
          news:uAYJPuQ4GH A.3644@TK2MSFTN GP03.phx.gbl...
          In VS.2005 using VB.NET
          >
          I have tried to make a string
          >
          dim abc as string
          abc = format(now,"mm/dd/yyyy")
          or
          abc format$(now,"mm/dd/yyyy")
          >
          but it doesn't work.
          >
          I get: 28/25/2006
          >
          the day and year are ok, but the month is always wrong,
          the month is something different every time,
          >
          Thanks in Advance,
          >
          Laurence

          Comment

          • Steven Nagy

            #6
            Re: Convert Now to a string

            Another answer besides those provided:

            Dim abc as string = DateTime.Now.To ShortDateString ()

            Comment

            • Laurence

              #7
              Re: Convert Now to a string

              Thank You,

              Laurence

              wilson wrote:
              Use MM for month with leading zero.
              mm is minute with leading zero.
              >
              Laurence wrote:
              >
              >In VS.2005 using VB.NET
              >>
              >I have tried to make a string
              >>
              >dim abc as string
              >abc = format(now,"mm/dd/yyyy")
              >or
              >abc format$(now,"mm/dd/yyyy")
              >>
              >but it doesn't work.
              >>
              >I get: 28/25/2006
              >>
              >the day and year are ok, but the month is always wrong,
              >the month is something different every time,
              >>
              >Thanks in Advance,
              >>
              >Laurence
              >
              >
              >

              Comment

              Working...