Convert.ToDateTime

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike P

    #1

    Convert.ToDateTime

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

    DateFrom = Convert.ToDateT ime(DateFrom.To String("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


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Jon Skeet [C# MVP]

    #2
    Re: Convert.ToDateT ime

    Mike P <mrp@telcoelect ronics.co.uk> wrote:[color=blue]
    > I've been using this code to get the date in the format dd/mm/yyyy with
    > Culture="en-GB":
    >
    > DateFrom = Convert.ToDateT ime(DateFrom.To String("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?[/color]

    Instead of changing your culture, use DateTime.ParseE xact and give it
    the appropriate format to parse, and then use DateTime.ToStri ng with
    the appropriate format to reformat it again.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    Working...