Kaja
Kaja

Reputation: 97

Date formatting from user input

Hai i am getting a date input(Not the DateTime.Now) from the user and i want that to transform and show in a Date format. E.g: in the XAML, will be specified and i want that to be shown as "PrintedOn - October 24,2008" .The string formatting is string.format("{0} - {1}",userText, userDate). Where am i going wrong?How can i convert the UserDate to the formatting i need. Please pecify the code. Thanks

Upvotes: 0

Views: 6216

Answers (3)

MartW
MartW

Reputation: 12538

Use this :

String.Format("{0} - {1}", userText, Date.Parse(userDate).ToString("MMMM dd,yyyy"))

where userDate is currently your date as an unspecified format in a string from the XAML. If you know the format it's arriving in, use ParseExact instead.

Upvotes: 1

jle
jle

Reputation: 9479

if you have a date from the user:

just use DateTime.ToString()

If you need to get a date from a string, just use

DateTime. Parse(datestring)

Upvotes: 0

Thomas
Thomas

Reputation: 181725

From your code sample, I assume this is C# or VB.NET.

String.Format("{0} - {1}", userText, userDate.ToString("D"))

does something along those lines, and gives you a string in the current locale as a bonus. See the possible format strings for more info.

Upvotes: 0

Related Questions