Hello, what can i do to convert a date that is dd/mm/yyyy to yyyy-mm-dd?

public static Paginacao<Solicitacao> PaginarParaLote(int paginaAtual = 0, int itensPorPagina = 20, int? TipoId = null, long? ProtocoloId = null, int? StatusId = null, DateTime? DataSolicitacaoInicio = null, DateTime? DataSolicitacaoFim = null)
        {
            StringBuilder strWhere = new StringBuilder();

            if (TipoId != null)
            {
                strWhere.AppendFormat(" AND TipoId = {0} ", TipoId);
            }
            if (ProtocoloId != null)
            {
                strWhere.AppendFormat(" AND ProtocoloId = {0} ", ProtocoloId);
            }
            if (StatusId != null)
            {
                strWhere.AppendFormat(" AND StatusId = {0} ", StatusId);
            }
            if (DataSolicitacaoInicio != null)
            {
                if (DataSolicitacaoFim != null)
                {
                    strWhere.AppendFormat(" AND DataInicioSolicitacao BETWEEN '{0}'  AND '{1}'", DataSolicitacaoInicio.Value.ToShortDateString(), DataSolicitacaoFim.Value.ToShortDateString());
                }
                else
                {
                    strWhere.AppendFormat(" AND DataInicioSolicitacao > {0} ", DataSolicitacaoInicio.Value.ToShortDateString());
                }
            }
            strWhere.AppendFormat(" AND Id NOT IN(SELECT SolicitacaoId FROM [Lote.Solicitacoes])");

            return PaginarWhere(paginaAtual, itensPorPagina, " Id ", strWhere.ToString());
        }

Thanks

Recommended Answers

All 4 Replies

Not this?
string ddd= DateTime.Now.ToString("yyyy-MM-dd");

Another possibility is this webpage

From the MSDN page I linked:

In formatting operations, custom date and time format strings can be used either with the ToString method of a date and time instance or with a method that supports composite formatting.

So...

string ddd= DateTime.Now.ToString("yyyy-MM-dd");

Another possibility is this webpage

Those are both correct. The former is "the ToString method", and the latter is "composite formatting".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.