Convert.ToDateTime

M

Mike P

I've been using this code to get the date in the format dd/mm/yyyy with
Culture="en-GB":

DateFrom = Convert.ToDateTime(DateFrom.ToString("d"));

Now I need to put the date in US format, so I've changed my Culture to
"en-US", but the line of code no longer works, instead of 10/28/2003, I
get 10/28/2003 12:00:00AM.

Can anybody help me out with this?



Thanks,

lfc77
 
J

Jon Skeet [C# MVP]

Mike P said:
I've been using this code to get the date in the format dd/mm/yyyy with
Culture="en-GB":

DateFrom = Convert.ToDateTime(DateFrom.ToString("d"));

Now I need to put the date in US format, so I've changed my Culture to
"en-US", but the line of code no longer works, instead of 10/28/2003, I
get 10/28/2003 12:00:00AM.

Can anybody help me out with this?

Instead of changing your culture, use DateTime.ParseExact and give it
the appropriate format to parse, and then use DateTime.ToString with
the appropriate format to reformat it again.
 

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

changing culture on datetimepicker 2
convert date to ticks 1
convert date 1
DateTime and localization 2
DateTIme help 2
Convert Date pb 2
Convert.ToDateTime ERROR 4
Date & time 2

Top