Created
May 1, 2023 22:18
-
-
Save fernandezja/29fbb6468ca0923e4a6f508ec6b4d169 to your computer and use it in GitHub Desktop.
LINQ: Datetime range without sunday / LINQ: Rango de fechas sin domingo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var inicio = new DateTime(2022, 12, 18); | |
var fin = new DateTime(2023, 5, 1); | |
var dias = Enumerable.Range(0, 1 + fin.Subtract(inicio).Days) | |
.Select(offset => inicio.AddDays(offset)) | |
.ToArray(); | |
var diasSinDomingo = Enumerable.Range(0, 1 + fin.Subtract(inicio).Days) | |
.Where(offset => (inicio.AddDays(offset)).DayOfWeek != DayOfWeek.Sunday) | |
.Select(offset => inicio.AddDays(offset)) | |
.ToArray(); | |
Console.WriteLine($" Dias en el rango: {dias.Count()}"); //dias en el rango: 135 | |
Console.WriteLine($" Dias en el rango (sin domingos): {diasSinDomingo.Count()}"); //dias en el rango: 115 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run here > https://dotnetfiddle.net/ZGPwLc