A string of this type as you have recorded in the database is not recognized as DateTime. It is necessary to take it apart. For this, there is a string.Split () method. Get the array. Zero item will be the day of the week.
string dt_str = row["dt_send_datetime"]; string[] dt_str_tmp = st_str.Split(':'); switch (row["name_ru"]) { case "Час": // Можно сразу так. В итоге получим к примеру 4:0 Console.WriteLine(dt_str_tmp[2]+":"+dt_str_tmp[3]); // Можно конвертировать во время // DateTime dt = DateTime.Parse(string.Format("{0}:{1}:{2}", dt_str_tmp[1], dt_str_tmp[2], dt_str_tmp[3])); // и потом вывести // Console.WriteLine(dt.ToString("mm:ss"); // В итоге получим 04:00 break; case "Неделя": Console.WriteLine(dt_str_tmp[0]); break; }
You can replace the whole switch , provided that the choice of only two values - "hour" or "week", with:
Console.WriteLine((name_ru == "Час")?dt_str_tmp[2]+":"+dt_str_tmp[3]:dt_str_tmp[0]);