Whatever programming language we  use,  we must be ever encounter converting & some kind problem with Date format variable , in java the solution is under my article Java – Convert String to Date, Date to String with SimpleDateFormat and now in C# here is the solution :

//author mdsaputra.wordpress.com | EtaYuy | Meihta Dwiguna Saputra
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TutorialConvertingDateTimeIntoString
    class Program
        static string dateFormat = "yyyyMMddHHmmss";
        static System.Globalization.DateTimeFormatInfo dti = new System.Globalization.DateTimeFormatInfo();

        static void Main(string[] args)
            DateTime dateTime = DateTime.Now;
            string dateInString = convertDateTimeToFormatedString(dateTime);
            Console.WriteLine("DateTime to String : " + dateInString);
            Console.WriteLine("String to DateTime : " +convertStringToDateTime(dateInString));

        //convert DateTime into Formated String
        public static string convertDateTimeToFormatedString(DateTime dateTime)
            return dateTime.ToString(dateFormat, dti);

        //convert Formatted String into DateTime
        public static DateTime convertStringToDateTime(string dateTimeInString)
            dti.LongTimePattern = dateFormat;
            return DateTime.ParseExact(dateTimeInString, "T", dti);

Here is running result of code above :

Twitter Subscribe :