Parse DateTime and Boolean

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
 
A

Arne Vajhøj

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
 
C

Cor Ligthert[MVP]

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

Cor
 
P

Pavel Minaev

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.
 
M

Michaela Julia

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 ...
 
J

Jeff Johnson

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....
 
S

shapper

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top