I wanted to convert date into DD/MM/YYYY/HH:MM:SS
format. the date is given by the user.
I am using the code below:
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) { }
I wanted to convert fromdate
and todate
into DD/MM/YYYY/HH:MM:SS
format. When I try to do this I get 01/01/0001/00:00:00
.
in FormatDate i have the code below:
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;
}