This is because your application does not define any culture. Therefore, the culture used will be the one defined in Windows.
Locally this will work because your Windows is configured with a culture (probably pt-*) and the date passed by parameter has the format used in this culture. On the server will not work because the culture is different, so the date format will not be valid.
If you know the formats beforehand and are sure they will always be the same, you can use a ParseExact
to convert the string
for DateTime
.
It is interesting you pay attention to these details of culture, maybe it is much better to take care of it than to use the ParseExact
, but without more details there’s no way to help you much.
public DataTable SelecionaConsulta(string dtaIni, string dtaFim)
{
var formato = "dd/MM/yyyy HH:mm:ss";
DateTime dataInicio;
var dtIniConvertida = DateTime.TryParseExact(dtaIni, formato, CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out dataInicio);
DateTime dataFim;
var dtFimConvertida = DateTime.TryParseExact(dtaFim, formato, CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out dataFim);
if(!dtIniConvertida && !dtFimConvertida)
//Algo deu errado em uma das conversões
return consulta.SELECT_VISITA(dataInicio.ToString("yyyyMMdd"), dataFim.ToString("yyyyMMdd"));
}