1

I am trying to get the current date, which works with the code that I have at the moment:

else if (e.KeyCode == Keys.Enter && InputTextbox.Text == "date")            
{
    OutputTextbox.Text = "Today is " + DateTime.Now.Date.ToString("dd");
    pBuilder.ClearContent();
    pBuilder.AppendText(OutputTextbox.Text);
    sSynth.Speak(pBuilder);
    e.SuppressKeyPress = true;
    InputTextbox.Text = ""; 
}

That gives me the date as a number (ie: 26).

I have done some research on other ways to put the "th", "rd", and "nd" on the end of the numbers, but is there a way to do this within the current "else if" statement that I have at the moment (the other solutions are in a seperate space).

svick
  • 225,720
  • 49
  • 378
  • 501
The Woo
  • 16,359
  • 26
  • 55
  • 68

1 Answers1

3

Consider modifying your code to include the following snippet of code...

string date = DateTime.Now.Date.ToString("dd");
    date = date + (date.EndsWith("11") 
                   ? "th"
                   : date.EndsWith("12")
                   ? "th"
                   : date.EndsWith("13")
                   ? "th"
                   : date.EndsWith("1") 
                   ? "st"
                   : date.EndsWith("2")
                   ? "nd"
                   : date.EndsWith("3")
                   ? "rd"
                   : "th");

Good Luck!

gpmurthy
  • 2,389
  • 18
  • 21