DateTime issue

MJ_AhmedMJ_Ahmed BHMember ✭✭

Hi all;

I have a string that looks like this:
string d="11/11/1993";

If I try to output it to a label as follows:
label1.Text=string.Format("MMM dd,yyyy",d);

it just shows this output in the label:
MMM dd,yyyy

but no date at all.....

How can I display it as Nov 11,1993 ?

Best Answers

Answers

  • MJ_AhmedMJ_Ahmed BHMember ✭✭
    edited November 2017

    @AlessandroCaliaro said:
    I think you have to convert "d" to a DateTime object with DateTime.TryParseExact, then you can format it

    I tried this:

    CultureInfo provider = CultureInfo.InvariantCulture;
    DateTime result;
    string format = "MMM dd,yyyy";
    result = DateTime.ParseExact(d, format, provider);
    DisplayAlert("OK",result.ToString(),"OK");

    but it crashes

  • MJ_AhmedMJ_Ahmed BHMember ✭✭
    edited November 2017

    @AlessandroCaliaro said:
    I think you have to convert "d" to a DateTime object with DateTime.TryParseExact, then you can format it

    worked like a charm, as per you said, I converted it to DateTime object and went with a simple approach:

            DateTime oDate = Convert.ToDateTime(d);
            string x = oDate.ToString("MMM dd,yyyy");
            date.Text = x;
    

    Thanks so much for the help !!! :)

Sign In or Register to comment.