|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
convet date formatHi, 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 On Wed, 6 Dec 2006 10:21:01 -0800, martin1 wrote:
> Hi, All, Hey Martin,> > 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 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")) 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 > On Wed, 6 Dec 2006 11:31:01 -0800, martin1 wrote:
> Thank you so much. it work Excellent! :)> > "Rad [Visual C# 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 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 >> On Thu, 7 Dec 2006 06:27:39 +0100, Cor Ligthert [MVP] wrote:
> Martin, True, but he gave the format of the date as MM/dd/yyyy. In any case, unless> > 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 > you use calendars or datepickers for your date entry and manipulation i don't see a magic bullet for this particular problem 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 martin1 wrote:
> Hi, All, Snice dates don't have an implicit format, I /assume/ you're dealing > > 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. 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.
Embedding a newline in a vb.net string constant
OLEDBCommand vs. SQLCommand MDI Parent Forms cUpdate Custom attribut with reflection Exe Size Re: Which do you prefer? XML File into a SQL table how pass Date vaiable to XPath query Setting Tab Index between Panels DLL returns a variant data type - how to convert and use in VB .NET |
|||||||||||||||||||||||