title: How to convert a date into DD/MM/YYYY/HH:MM:SS
body: <p>I wanted to convert date into <code>DD/MM/YYYY/HH:MM:SS</code> format. the date is given by the user.</p>
  
  <p>I am  using the code below:</p>
  
  <pre><code>        string fromdate = context.Request.QueryString["fromdate"];
          string todate = context.Request.QueryString["todatedate"];
  
          DateTime fromDaten = DateTime.MinValue;
          DateTime toDaten = DateTime.MinValue;
  
          try
          {
              fromDaten = FormatDate(fromdate + " 00:00:00");
              toDaten = FormatDate(todate + " 00:00:00");
          }
          catch (Exception ex) { }
  </code></pre>
  
  <p>I wanted to convert <code>fromdate</code> and <code>todate</code> into <code>DD/MM/YYYY/HH:MM:SS</code> format. When I try to do this I get <code>01/01/0001/00:00:00</code>.</p>
  
  <p>in FormatDate i have the code below:</p>
  
  <pre><code>        try
          {
  
              string dateTimeString = todate;
              dateTimeString = Regex.Replace(dateTimeString, @"[^\u0000-\u007F]", string.Empty);
  
              string inputFormat = "yyyy-MM-dd HH:mm:ss";
              string outputFormat = "dd-MM-yyyy HH:mm:ss";
              var dateTime = DateTime.ParseExact(dateTimeString, inputFormat, CultureInfo.InvariantCulture);
              string output = dateTime.ToString(outputFormat);
              return Convert.ToDateTime(output);
          }
          catch (Exception ex)
          {
              throw;
          }
  </code></pre>