desenvolvedor-io / desenvolvedor-io/dev-store

SQL Server Timezone

Open
#2 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
1.1k
Forks
224
PR merge metrics
No merged PRs in 30d

Description

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

At PedidoAPI:
![image](https://user-images.githubusercontent.com/7241156/127810627-77114fa2-43d5-4469-90d1-43709b448836.png)

But there are items at Database:
![image](https://user-images.githubusercontent.com/7241156/127810769-5ac02e9c-dd85-4a67-82c6-c0b243879a1b.png)

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

```c#
public async Task 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(sql, new { clienteId, Now = DateTime.Now });

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

return MapearPedido(pedido);
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.