dev-store icon indicating copy to clipboard operation
dev-store copied to clipboard

SQL Server Timezone

Open brunobritodev opened this issue 2 years ago • 1 comments

When running from local machine at Sql Server on Docker some queries get broken because the TimeZone.

At PedidoAPI: image

But there are items at Database: image

So, sending the "DateTime.Now" from API Backend it works:

      public async Task<PedidoDTO> ObterUltimoPedido(Guid clienteId)
        {
            const string sql = @"SELECT
                                P.ID AS 'ProdutoId', P.CODIGO, P.VOUCHERUTILIZADO, P.DESCONTO, P.VALORTOTAL,P.PEDIDOSTATUS,
                                P.LOGRADOURO,P.NUMERO, P.BAIRRO, P.CEP, P.COMPLEMENTO, P.CIDADE, P.ESTADO,
                                PIT.ID AS 'ProdutoItemId',PIT.PRODUTONOME, PIT.QUANTIDADE, PIT.PRODUTOIMAGEM, PIT.VALORUNITARIO 
                                FROM PEDIDOS P 
                                INNER JOIN PEDIDOITEMS PIT ON P.ID = PIT.PEDIDOID 
                                WHERE P.CLIENTEID = @clienteId 
                                AND P.DATACADASTRO between DATEADD(minute, -30,  @Now) and @Now
                                ORDER BY P.DATACADASTRO DESC";

            var pedido = await _pedidoRepository.ObterConexao()
                .QueryAsync<dynamic>(sql, new { clienteId, Now = DateTime.Now });

            if (!pedido.Any())
                return null;

            return MapearPedido(pedido);
        }

brunobritodev avatar Aug 02 '21 05:08 brunobritodev

Can I make a suggestion? I work with multi time zone application and the best solution is to work everything in UTC. Just like the plane works, that ZULU

wzuqui avatar Apr 21 '22 01:04 wzuqui