Failed to move from one Array of string to another of Dates C #

0

The error gives me inside the loop for , I need the date to enter the format of "days / months / years hours: minutes".

protected void Page_Load(object sender, EventArgs e)
{
    string strfechas = Request.QueryString["date"];

    char separator = ',';
    string[] fechas = strfechas.Split(separator);

    DateTime[] fechas1 = new DateTime[fechas.Length];


    for (int i = 0; i < fechas.Length; i++)
    {
        //fechas1[i] = Convert.ToDateTime(fechas[i]);
        fechas1[i] = DateTime.ParseExact(fechas[i], "MM/dd/yyyy HH:mm", CultureInfo.InvariantCulture);

    }''
    
asked by Igor 10.10.2018 в 12:29
source

1 answer

0

If the desired format is: "days / months / years hours: minutes"

and in your database you have saved this type of format:

"2017-11-28 17:30:22.000"

You just have to change the format to "yyyy-MM-dd HH: mm: ss.fff":

//    fechas1[i] = DateTime.ParseExact(fechas[i], "MM/dd/yyyy HH:mm", CultureInfo.InvariantCulture);
    fechas1[i] = DateTime.ParseExact(fechas[i], "yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
    
answered by 14.12.2018 в 22:46