Date format question
I have aporject that is en_GB globalized but the data base the project is reading is in US format, how can I convert the strings I have to US format but still read UK format on the GUI.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Amy TurnbullPosted Oct 24, 2007, 3:36 AM
string strSdate = (string) cdrCalendarStart.SelectedDate.ToShortDateString();
strSdate = String.Format("{0:MM/dd/yyyy 00:00.00}",strSdate);
string strFdate = (string) cdrCalendarFin.SelectedDate.ToShortDateString();
strFdate = String.Format("{0:MM/dd/yyyy 00:00.00}",strFdate);
Scott LyslePosted Oct 24, 2007, 12:01 AM
If you are doing this on a a case by case basis, you can use any of these:
public Form1() { InitializeComponent(); textBox1.Text = DateTime.Now.ToShortDateString(); } private void button1_Click(object sender, EventArgs e) { // using UI culture CultureInfo ciEnglishGB = new CultureInfo("en-GB"); DateTime dtGreatBritian = Convert.ToDateTime(textBox1.Text); textBox2.Text = dtGreatBritian.ToString(ciEnglishGB.DateTimeFormat.ShortDatePattern); } private void button2_Click(object sender, EventArgs e) { // e.g., 23/10/2007 string[] usDate = textBox1.Text.Split('/'); textBox2.Text = usDate[1] + "/" + usDate[0] + "/" + usDate[2]; } private void button3_Click(object sender, EventArgs e) { // e.g., 23/10/2007 string[] usDate = textBox1.Text.Split('/'); DateTime dtGreatBritain = new DateTime(Convert.ToInt32(usDate[2]), Convert.ToInt32(usDate[0]), Convert.ToInt32(usDate[1])); textBox2.Text = dtGreatBritain.ToString("dd/MM/yyyy"); } private void button4_Click(object sender, EventArgs e) { // text, abbreviated month (e.g., Oct) string[] usDate = textBox1.Text.Split('/'); DateTime dtGreatBritain = new DateTime(Convert.ToInt32(usDate[2]), Convert.ToInt32(usDate[0]), Convert.ToInt32(usDate[1])); textBox2.Text = dtGreatBritain.ToString("dd MMM, yyyy"); } private void button5_Click(object sender, EventArgs e) { // text, month spelled out (e.g., October) string[] usDate = textBox1.Text.Split('/'); DateTime dtGreatBritain = new DateTime(Convert.ToInt32(usDate[2]), Convert.ToInt32(usDate[0]), Convert.ToInt32(usDate[1])); textBox2.Text = dtGreatBritain.ToString("dd MMMM, yyyy"); }