FAST date string conversion ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pamelafluente@libero.it

    #1

    FAST date string conversion ?

    A quick question,

    I have a string with a date in european format, e.g. "30/4/2006".

    What is the FASTEST way to produce the corresponding string in USA
    format
    "4/30/2006" and asian format "2006/4/30" ?

    -pam

  • Jay B. Harlow [MVP - Outlook]

    #2
    Re: FAST date string conversion ?

    Pam,
    Define "fastest", I would be more concerned with the "proper" way of doing
    it.

    If I had a date in d/m/y format & wanted m/d/y or y/m/d formats I would
    simply use DateTime.Parse & DateTime.ToStri ng. As Parse & ToString are the
    "proper" ways of doing (who better then the type itself to have convert to &
    from various formats).

    Something like:

    Const dmy As String = "d/M/yyyy"
    Const mdy As String = "M/d/yyyy"
    Const ymd As String = "yyyy/M/d"

    Dim european As String = "30/4/2006"

    Dim someDate As Date = DateTime.ParseE xact(european, dmy, Nothing)

    Dim usa As String = someDate.ToStri ng(mdy)
    Dim asian As String = someDate.ToStri ng(ymd)

    NOTE: Convert.ToStrin g & Convert.ToDateT ime ultimately call DateTime.Parse &
    DateTime.ToStri ng...

    --
    Hope this helps
    Jay B. Harlow [MVP - Outlook]
    ..NET Application Architect, Enthusiast, & Evangelist
    T.S. Bradley - http://www.tsbradley.net


    <pamelafluente@ libero.it> wrote in message
    news:1148567185 .670632.305690@ u72g2000cwu.goo glegroups.com.. .
    |A quick question,
    |
    | I have a string with a date in european format, e.g. "30/4/2006".
    |
    | What is the FASTEST way to produce the corresponding string in USA
    | format
    | "4/30/2006" and asian format "2006/4/30" ?
    |
    | -pam
    |


    Comment

    • pamelafluente@libero.it

      #3
      Re: FAST date string conversion ?

      Thank you Jay, it helps a lot !

      I have a doubt, why for the year there are 4 yyyy and for day/month on
      one
      (intuitively one would expect 2 chars ).

      Thanks again,

      -pam

      PS by "fast" I meant the most efficient way in terms of speed of
      execution. Probably the one you suggest :-)

      Comment

      • Jay B. Harlow [MVP - Outlook]

        #4
        Re: FAST date string conversion ?

        I used one on day & month so as to allow the 1st thru the 9th. without
        requiring a leading zero.

        It allows "30/4/2006" rather then require "30/04/2006"


        --
        Hope this helps
        Jay B. Harlow [MVP - Outlook]
        ..NET Application Architect, Enthusiast, & Evangelist
        T.S. Bradley - http://www.tsbradley.net


        <pamelafluente@ libero.it> wrote in message
        news:1148573460 .120392.182790@ y43g2000cwc.goo glegroups.com.. .
        | Thank you Jay, it helps a lot !
        |
        | I have a doubt, why for the year there are 4 yyyy and for day/month on
        | one
        | (intuitively one would expect 2 chars ).
        |
        | Thanks again,
        |
        | -pam
        |
        | PS by "fast" I meant the most efficient way in terms of speed of
        | execution. Probably the one you suggest :-)
        |


        Comment

        • pamelafluente@libero.it

          #5
          Re: FAST date string conversion ?

          Very good. Thank you very much!

          I guess that with the same logic it could be safe to use only 2 chars
          for the year (yy) ...

          -pam

          Comment

          • Cor Ligthert [MVP]

            #6
            Re: FAST date string conversion ?

            Jay,

            Just for you as American,
            [color=blue]
            > It allows "30/4/2006" rather then require "30/04/2006"[/color]

            The second is AFAIK more common in Europe, that as well for the days.

            Cor

            [color=blue]
            >
            >
            > --
            > Hope this helps
            > Jay B. Harlow [MVP - Outlook]
            > .NET Application Architect, Enthusiast, & Evangelist
            > T.S. Bradley - http://www.tsbradley.net
            >
            >
            > <pamelafluente@ libero.it> wrote in message
            > news:1148573460 .120392.182790@ y43g2000cwc.goo glegroups.com.. .
            > | Thank you Jay, it helps a lot !
            > |
            > | I have a doubt, why for the year there are 4 yyyy and for day/month on
            > | one
            > | (intuitively one would expect 2 chars ).
            > |
            > | Thanks again,
            > |
            > | -pam
            > |
            > | PS by "fast" I meant the most efficient way in terms of speed of
            > | execution. Probably the one you suggest :-)
            > |
            >
            >[/color]


            Comment

            Working...