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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Scott LysleRank #49 · 31K reputationPosted Oct 23, 2007, 8:01 PM EDT
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"); }Amy Turnbull21 reputationPosted Oct 23, 2007, 11:36 PM EDT
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);