Filter children on date
# help-with-umbraco
c
Umb 10.6.1 Can anyone spot what the issue with this line is please?
Copy code
List<WeeklyEventItem> weeklyEventList = CurrentPage.Children<WeeklyEventItem>().Where(x => x.RepeatableStartDate.Date >= DateTime.Today).ToList();
It returns everything if I leave the Where clause out. But won't filter on the date.
d
The datetime that you get from the childpages, is it a utc date or a local date? I believe datetimes are transformed in someway during comparison when one is utc and the other isn't
c
It's just an Umbraco DateTime
Outside this line, within the foreach loop dealing with the results, the RepeatableStartDate is operating as expected, just not in this linq query 😦
d
Understandable, but you're using 'today' to compare against, which has a property 'kind' set as 'local'. If the 'kind' property of the datetime from 'RepeatableStartDate' is not 'local' as well, a transform is applied before comparison
c
Interesting. I've just tried:-
RepeatableStartDate.Date >= DateTime.Today
RepeatableStartDate.Date >= DateTime.UtcNow
RepeatableStartDate.Date >= DateTime.Now
RepeatableStartDate >= DateTime.UtcNow
RepeatableStartDate >= DateTime.Now
And have tried removing the "=" so it's just ">" And converting both sides to Ticks. Nothing works 😦
d
Alright, now just so I fully comprehend, what is the outcome that you get? I'm assuming you're looking for all items with a RepeatableStartDate in the future, including today. Do you get nothing at all? or are you missing certain items that you expected in your output? And just as an inspiring anecdote: I had pulled open a project once that hadn't been touched for a while and dates also didn't seem to work anymore. Turned out I had forgotten to update the dates in the content, because all the dates in the content had expired.
c
Lol, yeah, had that one before 🙂 You're correct, in that I want all the nodes with a RepeatableStartDate in the future, incl. today. I get 0 out. There are over 700 records with dates ranging from 2019 to 2024.
Oh Dear, it appears I also had that one again! The test data was changed on me!