473,491 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Datetime.Parse

Hi there

I would like some help with parsing date strings to DateTime structures.

I can see that DateTime has Parse and ParseExact methods - but I am not sure
what is best for me to use, and what parameters I need to supply.

I reveive a string from a web-form, which would look something like this:
"31-12-1999 14:56:22"; and I need to parse it to a DateTime

The ParseExact method has one form that looks like this:
ParseExact(string s, string format, IFormatProvider provider)
but I don't understand what the format-provider is or why it is required,
and how it is different from the supplied format.

Any one have some good suggestions for converting strings to DateTimes?

Thanks for any help,
Peter
Nov 17 '05 #1
2 4826
Hi Peter,

Normally I will write an answer myself, but this time the msdn-guys have
done a great job :-)

Look for info on that ParseExact method at
http://msdn.microsoft.com/library/de...xacttopic3.asp
and for more info on datetimeformats at
http://msdn.microsoft.com/library/de...classtopic.asp

Combining the two helptexts should help you along...(look extra careful at
the 'expectedFormats' in the given example of the ParseExact method)

Cheers,
Christiaan

"Peter Kirk" <pk@alpha-solutions.dk> schreef in bericht
news:e$**************@TK2MSFTNGP15.phx.gbl...
Hi there

I would like some help with parsing date strings to DateTime structures.

I can see that DateTime has Parse and ParseExact methods - but I am not
sure what is best for me to use, and what parameters I need to supply.

I reveive a string from a web-form, which would look something like this:
"31-12-1999 14:56:22"; and I need to parse it to a DateTime

The ParseExact method has one form that looks like this:
ParseExact(string s, string format, IFormatProvider provider)
but I don't understand what the format-provider is or why it is required,
and how it is different from the supplied format.

Any one have some good suggestions for converting strings to DateTimes?

Thanks for any help,
Peter

Nov 17 '05 #2
Another reason (I think) for the IFormatProvider: imagine a date like this
"08-07-1999 14:56:22". Is this refering to the seventh day of August (USA
format), or the eighth day July (European).

I once saw an old post enlightening me that there were six (?) ways to
interpret "04-05-03", hence the need for this kind of formating info.

scott

"Peter Kirk" <pk@alpha-solutions.dk> wrote in message
news:e$**************@TK2MSFTNGP15.phx.gbl...
Hi there

I would like some help with parsing date strings to DateTime structures.

I can see that DateTime has Parse and ParseExact methods - but I am not
sure what is best for me to use, and what parameters I need to supply.

I reveive a string from a web-form, which would look something like this:
"31-12-1999 14:56:22"; and I need to parse it to a DateTime

The ParseExact method has one form that looks like this:
ParseExact(string s, string format, IFormatProvider provider)
but I don't understand what the format-provider is or why it is required,
and how it is different from the supplied format.

Any one have some good suggestions for converting strings to DateTimes?

Thanks for any help,
Peter

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
3709
by: ChrisM | last post by:
Could anyone please tell me the difference between these 2 lines: myDate = DateTime.Now; and myDate = DateTime.Parse(DateTime.Now.ToString("dd/MM/yyyy")); Seeing as later on in the...
1
13286
by: vooose | last post by:
Consider an application which has *many* references to DateTime.Parse(string); Is there a way, say when the application first starts up to force this method to use a specific IFormatProvider,...
4
18152
by: Hans Merkl | last post by:
Does anybody know of a library that can handle strings pf various formats and conver them to a DateTime value? The strings are coming from a webform and I can't restrict the input (it's not my...
6
8962
by: Ante Perkovic | last post by:
Hi, How to declare datetime object and set it to my birthday, first or last day of this month or any other date. I can't find any examples in VS.NET help! BTW, what is the difference...
38
807
by: nobody | last post by:
I know that given a FormatString and a DateTime you can use DateTime.ToString(...) to convert the DateTime to a String. My question is how can you turn that around? Given a String and a...
11
7162
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why...
11
2791
by: Tim | last post by:
Hi, I am trying to do something simple. Convert a string date to datetime but it is not working and is giving me a baffling error! System.Convert.ToDateTime("Jan 30, 2006")...
4
35834
by: tshad | last post by:
Is there any difference between convert.ToDateTime and System.DateTime.Parse? I am using them both and they seem the same. Is one better to use than another? Thanks, Tom
5
5124
by: js | last post by:
I have a textbox contains text in the format of "yyyy/MM/dd hh:mm:ss". I need to parse the text using System.DateTime.Parse() function with custom format. I got an error using the following code. ...
4
3677
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I am having a problem formatting a string when the time is in format hh.mm.ss - used in Europe Parse seems ok when the date uses "/" or "." as seperator but I get an exception when time...
0
7115
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6978
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7360
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5451
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4578
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3086
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1392
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
280
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.