Home All Groups Group Topic Archive Search About

FAST date string conversion ?

Author
25 May 2006 2:26 PM
pamelafluente
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

Author
25 May 2006 3:01 PM
Jay B. Harlow [MVP - Outlook]
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.ToString. 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.ParseExact(european, dmy, Nothing)

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

NOTE: Convert.ToString & Convert.ToDateTime ultimately call DateTime.Parse &
DateTime.ToString...

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


<pamelaflue***@libero.it> wrote in message
Show quoteHide quote
news:1148567185.670632.305690@u72g2000cwu.googlegroups.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
|
Author
25 May 2006 4:11 PM
pamelafluente
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 :-)
Author
25 May 2006 5:26 PM
Jay B. Harlow [MVP - Outlook]
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


<pamelaflue***@libero.it> wrote in message
Show quoteHide quote
news:1148573460.120392.182790@y43g2000cwc.googlegroups.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 :-)
|
Author
25 May 2006 8:55 PM
pamelafluente
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
Author
25 May 2006 9:34 PM
Cor Ligthert [MVP]
Jay,

Just for you as American,

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

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

Cor


Show quoteHide quote
>
>
> --
> Hope this helps
> Jay B. Harlow [MVP - Outlook]
> .NET Application Architect, Enthusiast, & Evangelist
> T.S. Bradley - http://www.tsbradley.net
>
>
> <pamelaflue***@libero.it> wrote in message
> news:1148573460.120392.182790@y43g2000cwc.googlegroups.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 :-)
> |
>
>