Home All Groups Group Topic Archive Search About
Author
6 Dec 2006 6:21 PM
martin1
Hi, All,

I want to convert Date mm/dd/yyyy to yyyy-mm-dd string, for example
05/29/2006 to 2006-05-29, can anyone help thi sout? Thanks.

Martin

Author
6 Dec 2006 7:08 PM
Rad [Visual C# MVP]
On Wed, 6 Dec 2006 10:21:01 -0800, martin1 wrote:

> Hi, All,
>
> I want to convert Date mm/dd/yyyy to yyyy-mm-dd string, for example
> 05/29/2006 to 2006-05-29, can anyone help thi sout? Thanks.
>
>  Martin

Hey Martin,

try this small program. Import System.Globalization first

dim myDate as Date
dim stringDate as string = "05/29/2006"
myDate=DateTime.ParseExact(stringDate, _
"MM/dd/yyyy",nothing,DateTimeStyles.None)
Console.WriteLine(myDate.ToString("yyyy-MM-dd"))
Author
6 Dec 2006 7:31 PM
martin1
Thank you so much. it work

Show quoteHide quote
"Rad [Visual C# MVP]" wrote:

> On Wed, 6 Dec 2006 10:21:01 -0800, martin1 wrote:
>
> > Hi, All,
> >
> > I want to convert Date mm/dd/yyyy to yyyy-mm-dd string, for example
> > 05/29/2006 to 2006-05-29, can anyone help thi sout? Thanks.
> >
> >  Martin
>
> Hey Martin,
>
> try this small program. Import System.Globalization first
>
> dim myDate as Date
> dim stringDate as string = "05/29/2006"
> myDate=DateTime.ParseExact(stringDate, _
> "MM/dd/yyyy",nothing,DateTimeStyles.None)
> Console.WriteLine(myDate.ToString("yyyy-MM-dd"))
> --
> Bits.Bytes
> http://bytes.thinkersroom.com
>
Author
6 Dec 2006 8:12 PM
Rad [Visual C# MVP]
On Wed, 6 Dec 2006 11:31:01 -0800, martin1 wrote:

> Thank you so much. it work
>
> "Rad [Visual C# MVP]" wrote:

Excellent! :)
Author
7 Dec 2006 5:27 AM
Cor Ligthert [MVP]
Martin,

Be aware that this piece of code can bring you in big trouble as you are by
instance developing outside the USA on a computer with US settings while
your clients are using non USA setting.

This is almost for every place on the world outside the USA and Coca Cola
cultures.

Cor

Show quoteHide quote
"martin1" <mart***@discussions.microsoft.com> schreef in bericht
news:6EDA377E-948F-4323-8B85-E8C023055FEE@microsoft.com...
> Thank you so much. it work
>
> "Rad [Visual C# MVP]" wrote:
>
>> On Wed, 6 Dec 2006 10:21:01 -0800, martin1 wrote:
>>
>> > Hi, All,
>> >
>> > I want to convert Date mm/dd/yyyy to yyyy-mm-dd string, for example
>> > 05/29/2006 to 2006-05-29, can anyone help thi sout? Thanks.
>> >
>> >  Martin
>>
>> Hey Martin,
>>
>> try this small program. Import System.Globalization first
>>
>> dim myDate as Date
>> dim stringDate as string = "05/29/2006"
>> myDate=DateTime.ParseExact(stringDate, _
>> "MM/dd/yyyy",nothing,DateTimeStyles.None)
>> Console.WriteLine(myDate.ToString("yyyy-MM-dd"))
>> --
>> Bits.Bytes
>> http://bytes.thinkersroom.com
>>
Author
7 Dec 2006 7:00 PM
Rad [Visual C# MVP]
On Thu, 7 Dec 2006 06:27:39 +0100, Cor Ligthert [MVP] wrote:

> Martin,
>
> Be aware that this piece of code can bring you in big trouble as you are by
> instance developing outside the USA on a computer with US settings while
> your clients are using non USA setting.
>
> This is almost for every place on the world outside the USA and Coca Cola
> cultures.
>
> Cor
>


True, but he gave the format of the date as MM/dd/yyyy. In any case, unless
you use calendars or datepickers for your date entry and manipulation i
don't see a magic bullet for this particular problem
Author
8 Dec 2006 5:48 AM
Cor Ligthert [MVP]
Rad,

That he will see as many Dutch, Danish, Swedish, etc developers use a USA OS
setting before him.

His clients are however in those countries most probably working with a
native OS. That shows than dd/MM/yyyy. Converting that can give big
problems, not only in the programming however as well in real money.

Beside that is VB.Net still reporting all dates while debugging and in
intelisence in USA format.

Cor

Show quoteHide quote
"Rad [Visual C# MVP]" <nospam@nospam.com> schreef in bericht
news:qi0pdw7l2915$.dlg@thinkersroom.com...
> On Thu, 7 Dec 2006 06:27:39 +0100, Cor Ligthert [MVP] wrote:
>
>> Martin,
>>
>> Be aware that this piece of code can bring you in big trouble as you are
>> by
>> instance developing outside the USA on a computer with US settings while
>> your clients are using non USA setting.
>>
>> This is almost for every place on the world outside the USA and Coca Cola
>> cultures.
>>
>> Cor
>>
>
>
> True, but he gave the format of the date as MM/dd/yyyy. In any case,
> unless
> you use calendars or datepickers for your date entry and manipulation i
> don't see a magic bullet for this particular problem
> --
> Bits.Bytes
> http://bytes.thinkersroom.com
Author
7 Dec 2006 11:33 AM
Phill W.
martin1 wrote:
> Hi, All,
>
> I want to convert Date mm/dd/yyyy to yyyy-mm-dd string, for example
> 05/29/2006 to 2006-05-29, can anyone help thi sout? Thanks.

Snice dates don't have an implicit format, I /assume/ you're dealing
with strings here and so, to avoid any [regional] ambiguity in the date
values that parsing might cause, how about:

Dim sDate1 As String = "05/29/2006"
Dim sDate2 As String _
    = sDate1.Substring( 6, 4 ) _
    & "-" & sDate1.Substring( 3, 4 ) _
    & "-" & sDate1.Substring( 1, 2 )

HTH,
    Phill  W.