By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,120 Members | 1,799 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,120 IT Pros & Developers. It's quick & easy.

converting string to date

P: n/a
hello!

Anybody knows if there is a method in C#, that can convert date given as
string, using date format given as string (like DD/MM/YYYY, DD-MM-YYYY) ?

Please help!
I couldn't find it in MSDN!

Thanks
Daniel
Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Daniel Patriak <Da************@bielbit.com.pl> wrote:
Anybody knows if there is a method in C#, that can convert date given as
string, using date format given as string (like DD/MM/YYYY, DD-MM-YYYY) ?


Look at DateTime.ParseExact.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

P: n/a
Ok, but how to force this method to respect my format. There was usend
culture in example, but all I have is date format as a string. I don't know
how to create Culture using this format.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Daniel Patriak <Da************@bielbit.com.pl> wrote:
Anybody knows if there is a method in C#, that can convert date given as
string, using date format given as string (like DD/MM/YYYY, DD-MM-YYYY)
?
Look at DateTime.ParseExact.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3

P: n/a
Daniel Patriak <Da************@bielbit.com.pl> wrote:
Ok, but how to force this method to respect my format. There was usend
culture in example, but all I have is date format as a string. I don't know
how to create Culture using this format.


You can specify Culture.InvariantCulture. You specify the format as
another of the parameters.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

P: n/a
Ok, that works. BIG THANKS. I've lost much time for searching.

Greetings from Poland!!!

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Daniel Patriak <Da************@bielbit.com.pl> wrote:
Ok, but how to force this method to respect my format. There was usend
culture in example, but all I have is date format as a string. I don't know how to create Culture using this format.


You can specify Culture.InvariantCulture. You specify the format as
another of the parameters.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #5

P: n/a
Hi Daniel,

Or, if you want custom format you might do something like:
string datestr = "21/01/2004";

CultureInfo ci = new CultureInfo("sl-SI", true);

ci.DateTimeFormat.DateSeparator = "/";

ci.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";

DateTime date = DateTime.Parse(datestr, ci);
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Daniel Patriak" <Da************@bielbit.com.pl> wrote in message
news:c8**********@nemesis.news.tpi.pl...
hello!

Anybody knows if there is a method in C#, that can convert date given as
string, using date format given as string (like DD/MM/YYYY, DD-MM-YYYY) ?

Please help!
I couldn't find it in MSDN!

Thanks
Daniel

Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.