Odd date.tostring problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?TWFydGluVGVlZnk=?=

    Odd date.tostring problem

    Hi,

    I need to write todays date incremented by one month as part of a string for
    a licence but i'm getting odd results as the tostring function is extracting
    the middle data section of the datetime variable:

    Dim dTrialExpiryDat e As DateTime = DateTime.Now.Ad dMonths(1)

    This give the value 13/07/2008 13:52:05

    I now want to change this value to 07/13/2008

    sTrialExpiryStr ing = dTrialExpiryDat e.ToString("mm/dd/yyyy")

    but the string contains 52/13/2008 i.e. it takes the 2008 13:52 from the
    middle section of the datetime variable???

    Any ideas
    Thanks

  • =?Utf-8?B?TWFydGluVGVlZnk=?=

    #2
    RE: Odd date.tostring problem

    I thought i'd fixed it but no

    I changed the declaration to

    Dim dTrialExpiryDat e As Date = Date.Now.AddMon ths(1)

    This gives 13/07/2008 14:02:46 (i expected 13/07/2008) and the tostring call
    gives 02/13/2008

    Now i'm really confused...

    "MartinTeef y" wrote:
    Hi,
    >
    I need to write todays date incremented by one month as part of a string for
    a licence but i'm getting odd results as the tostring function is extracting
    the middle data section of the datetime variable:
    >
    Dim dTrialExpiryDat e As DateTime = DateTime.Now.Ad dMonths(1)
    >
    This give the value 13/07/2008 13:52:05
    >
    I now want to change this value to 07/13/2008
    >
    sTrialExpiryStr ing = dTrialExpiryDat e.ToString("mm/dd/yyyy")
    >
    but the string contains 52/13/2008 i.e. it takes the 2008 13:52 from the
    middle section of the datetime variable???
    >
    Any ideas
    Thanks
    >

    Comment

    • Chris Dunaway

      #3
      Re: Odd date.tostring problem

      On Jun 13, 8:01 am, MartinTeefy
      <MartinTe...@di scussions.micro soft.comwrote:
      sTrialExpiryStr ing = dTrialExpiryDat e.ToString("mm/dd/yyyy")
      >
      but the string contains 52/13/2008 i.e. it takes the 2008 13:52 from the
      middle section of the datetime variable???
      >
      Your format string is incorrect. You are using ToString("mm/dd/yyyy")
      when you should be using ToString("MM/dd/yyyy"). Lower case mm gives
      you minutes, while upper case MM gives you the month.

      Chris

      Comment

      • =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=

        #4
        Re: Odd date.tostring problem

        MartinTeefy wrote:
        Hi,
        >
        I need to write todays date incremented by one month as part of a string for
        a licence but i'm getting odd results as the tostring function is extracting
        the middle data section of the datetime variable:
        >
        Dim dTrialExpiryDat e As DateTime = DateTime.Now.Ad dMonths(1)
        >
        This give the value 13/07/2008 13:52:05
        >
        I now want to change this value to 07/13/2008
        >
        sTrialExpiryStr ing = dTrialExpiryDat e.ToString("mm/dd/yyyy")
        >
        but the string contains 52/13/2008 i.e. it takes the 2008 13:52 from the
        middle section of the datetime variable???
        >
        Any ideas
        Thanks
        >
        That's not odd at all. The "mm" part of the format string doesn't stand
        for months, it stands for minutes.

        Use "MM/dd/yyyy".

        --
        Göran Andersson
        _____
        Göran Anderssons privata hemsida.

        Comment

        • Cor Ligthert[MVP]

          #5
          Re: Odd date.tostring problem

          Hi Martin,

          Some people gives us always a smile, but don't bother, I think we all have
          gone once in this trap.

          :-)

          Cor

          "MartinTeef y" <MartinTeefy@di scussions.micro soft.comschreef in bericht
          news:E58599A9-837C-45DE-96CA-A902F515F316@mi crosoft.com...
          Hi,
          >
          I need to write todays date incremented by one month as part of a string
          for
          a licence but i'm getting odd results as the tostring function is
          extracting
          the middle data section of the datetime variable:
          >
          Dim dTrialExpiryDat e As DateTime = DateTime.Now.Ad dMonths(1)
          >
          This give the value 13/07/2008 13:52:05
          >
          I now want to change this value to 07/13/2008
          >
          sTrialExpiryStr ing = dTrialExpiryDat e.ToString("mm/dd/yyyy")
          >
          but the string contains 52/13/2008 i.e. it takes the 2008 13:52 from the
          middle section of the datetime variable???
          >
          Any ideas
          Thanks
          >

          Comment

          • Steve Gerrard

            #6
            Re: Odd date.tostring problem

            Cor Ligthert[MVP] wrote:
            Hi Martin,
            >
            Some people gives us always a smile, but don't bother, I think we all
            have gone once in this trap.
            >
            :-)
            >
            Cor
            >
            Just once? :)


            Comment

            Working...