Sintaxe
M
fnHorasEntreDatas(Start as datetime, End as datetime) as listParâmetros
- StartdatetimeObrigatório
Início. Os minutos de Start se repetem em todos os itens.
M#datetime(2018, 7, 8, 1, 0, 0)- EnddatetimeObrigatório
Fim, inclusive.
M#datetime(2018, 7, 8, 4, 29, 0)
Tipo de retorno
list
Exemplos
M
fnHorasEntreDatas(#datetime(2018, 7, 8, 1, 0, 0), #datetime(2018, 7, 8, 4, 29, 0))
// {1:00, 2:00, 3:00, 4:00} de 08/07/2018
fnHorasEntreDatas(#datetime(2025, 2, 1, 0, 0, 0), #datetime(2025, 2, 2, 0, 0, 0))
// 25 itens: inclui 00:00 do dia seguinteCódigo completo
M
let
fnHorasEntreDatas = (Start as datetime, End as datetime) as list =>
if End < Start then {}
else List.Transform(
{0 .. Number.RoundDown(Duration.TotalHours(End - Start))},
each Start + #duration(0, _, 0, 0)
),
Documentacao = [
Documentation.Name = "fnHorasEntreDatas",
Documentation.Description = "Lista de datas/horas de hora em hora entre Start e End.",
Documentation.LongDescription = "Começa em Start e soma uma hora por item enquanto não passar de End (inclusive). End anterior a Start retorna lista vazia.",
Documentation.Category = "Data e hora",
Documentation.Source = "https://github.com/ImkeF/M",
Documentation.Author = "Imke Feldmann, adaptado por Paulo André Jesus",
Documentation.Version = "1.2",
Documentation.Examples = {
[Description = "Das 1:00 às 4:29", Code = "fnHorasEntreDatas(#datetime(2018, 7, 8, 1, 0, 0), #datetime(2018, 7, 8, 4, 29, 0))",
Result = "{#datetime(2018, 7, 8, 1, 0, 0), #datetime(2018, 7, 8, 2, 0, 0), #datetime(2018, 7, 8, 3, 0, 0), #datetime(2018, 7, 8, 4, 0, 0)}"],
[Description = "24 horas exatas: 25 itens, inclui o fim", Code = "fnHorasEntreDatas(#datetime(2025, 2, 1, 0, 0, 0), #datetime(2025, 2, 2, 0, 0, 0))",
Result = "{#datetime(2025, 2, 1, 0, 0, 0), ..., #datetime(2025, 2, 2, 0, 0, 0)}"]
}
]
in
Value.ReplaceType(fnHorasEntreDatas, Value.ReplaceMetadata(Value.Type(fnHorasEntreDatas), Documentacao))Mais informações
- Fonte
- Imke Feldmann, adaptado por Paulo André Jesus
- Versão
- 1.2
- Referência
- https://github.com/ImkeF/M