Re: Converting a date string to a DateTime. Example please

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



This is exactly what I have been looking for.
So simple, and without all that unnecessary IFormatProvider and CultureInfo
stuff.

THANK YOU!


"James Curran" <JamesCurran@xxxxxxxx> skrev i en meddelelse
news:uaazAB$zFHA.3896@xxxxxxxxxxxxxxxxxxxxxxx
>I think your main problem is that your format string is wrong:
>
> DateTime dt = DateTime.ParseExact(
> "13-10-05 10:19:26",
> "dd-MM-yy hh:mm:ss", null);
>
> Console.WriteLine(dt.ToString("F"));
>
> Prints: Thursday, October 13, 2005 10:19:26 AM
>
>
> Kim Hellan wrote:
>>>>> string strDate = "13-10-05 10:19:26";
>>>>> DateTime dtmDate = DateTime.Parse(strDate);
>>>>
>>>> Okay, lets say the date string is: "07-11-05 10:19:26".
>>>> How does the simple Parse() method above then know what is year,
>>>> month and day?
>>>
>>> It does not, therefore you should only use the DateTime.Parse (or if
>>> you use VBNet the than easier one for that CDate), if it comes from
>>> an input control as the textbox (and than it should be the installed
>>> culture way and go automaticly).
>>>
>>> If you use it on internet, than you should be sure that you have
>>> showed the datetime format mask beside the box.
>>>
>>> You can on Internet try to get the location from which it comes
>>> (that is not standard) and than assume the culture, however this is
>>> in my opinion real dangerous, because in by instance in Canada are
>>> two complete different date format paterns used.
>>>
>>> I hope this helps,
>>
>> Thank you, but my initial question still stands.
>> Can anybody give me a C# EXAMPLE of how to parse the "13-10-05
>> 10:19:26" string.
>> The string always have the format "DD-MM-YY hh:mm:ss" and the parsing
>> should work on ANY machine, ANYWHERE in the world, regardless of
>> culture/date settings on the computer used.
>>
>> Thank You!
>> Kim
>
> --
> Truth,
> James Curran [erstwhile-MVP]
> Home: www.noveltheory.com Work: www.njtheater.com
> Blog: www.honestillusion.com Day Job: www.partsearch.com
>


.



Relevant Pages

  • Re: Inserting regional settings specific data into sql server
    ... Italianyou will observe that the settings used are 10/02/2006 ... it a better idea to Format it using the string format functions or a very ... into the sql database.Sorry to bug the shorts off you but u now have context ... By using the parameters, while the program is in the right culture setting, ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Converting a date string to a DateTime. Example please
    ... I think your main problem is that your format string is wrong: ... Kim Hellan wrote: ... >> culture way and go automaticly). ... >> showed the datetime format mask beside the box. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: dateTime Manupulations
    ... I just following the advice from the VBNet pages to use the Convert ... Although when those advices were not given do I find them very clear to use ... format string, particulary wants to use change a format not in his own ... > Why are you arbitrarily picking a Culture to get a specific date format? ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Calender Control - CultureInfo question
    ... I keep the code in English format ... simply create a thread in the users culture (np - I have it stored as ... Steve ... > You'll need to do this on each and every request. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: compile+link Fujitsu Linux
    ... But when using OS standard format such as ELF, ... the norms of that format and culture. ... There is a single Unix Standard, now called the Single UNIX Specification, ...
    (comp.lang.cobol)