Parse DateTime and Boolean

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

How can I parse (or at least try) the following:

- A String representation of a DateTime to a DateTime
- A String representation of a Boolean to a boolean

Thanks,
Miguel
 
shapper said:
How can I parse (or at least try) the following:

- A String representation of a DateTime to a DateTime
- A String representation of a Boolean to a boolean

DateTime.Parse
DateTime.ParseExact
DateTime.TryParse
DateTime.TryParseExact
bool.Parse
bool.TryParse

Arne
 
DateTime.TryParse (many overloads)
DateTime.Parse(many overloads)
bool whatever = (expression)

Cor
 
DateTime.Parse
DateTime.ParseExact
DateTime.TryParse
DateTime.TryParseExact
bool.Parse
bool.TryParse

And also Convert.ToXXX

Of course, it also depends on the exact string representation of date
and boolean. E.g. I'm sure that Boolean.Parse() can handle "true" or
"false" case-insensitively, but I'm not so sure about e.g. "yes/no",
if that is needed.
 
Pavel said:
Of course, it also depends on the exact string representation of date
and boolean. E.g. I'm sure that Boolean.Parse() can handle "true" or
"false" case-insensitively, but I'm not so sure about e.g. "yes/no",
if that is needed.

I'm quite sure, for boolean, a switch construct might be a far better
solution ...
 
Of course, it also depends on the exact string representation of date
and boolean. E.g. I'm sure that Boolean.Parse() can handle "true" or
"false" case-insensitively, but I'm not so sure about e.g. "yes/no",
if that is needed.

I'm pretty sure Boolean cannot handle yes/no or 1/0. So sure that I wrote a
utility class method to do just that....
 
DateTime.Parse
DateTime.ParseExact
DateTime.TryParse
DateTime.TryParseExact
bool.Parse
bool.TryParse

This was exactly what I needed. I am using:
Boolean published;
article.Published = Boolean.TryParse(request.Form.Get
("Published"), out published),

Thank You,
Miguel
 
Back
Top