Click here to Skip to main content
15,913,487 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have a textbox containing value = 251210 (ddmmyy)

I want to convert this value = 20101225 (yyyymmdd)
Posted
Updated 8-Mar-10 0:13am
v3

string inp = textBox1.Text;
DateTime dt = DateTime.ParseExact(inp, "ddMMyy", System.Globalization.CultureInfo.InvariantCulture);
string outp = dt.ToString("yyyyMMdd");
 
Share this answer
 
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CodeProjectAnswer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            DateTime d = DateTime.Now;
            string date = DateTime.Now.ToString("ddMMyy");
            txtDate.Text = date.ToString();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string DayMonthYear="";
            string cdate = txtDate.Text.ToString();
            if (cdate.Length > 0)
            {
               string day=cdate.Substring(0, 2);
               string month = cdate.Substring(2, 2);
               string year = cdate.Substring(4, 2);
               if (DateTime.Now.ToString("yy") == year)
               {
                   DayMonthYear = DateTime.Now.ToString("yyyy");
                   if (DateTime.Now.ToString("MM") == month)
                   {
                       DayMonthYear += DateTime.Now.ToString("MM");
                       if (DateTime.Now.ToString("dd") == day)
                       {
                           DayMonthYear += DateTime.Now.ToString("dd");
                           txtConvertDate.Text = DayMonthYear.ToString();
                       }
                   }
               }
            }
        }
    }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900