Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
I have a disruption feed which displays disruptions happening now and disruptions happening in the future.
I have the live feed working like this:
var liveFiltered = disruptions.Where(x => x.Value<DateTime>("startDateTime") <= DateTime.Now.Date) .Where(x => x.Value<DateTime>("endDateTime") >= DateTime.Now.Date);
but we have a few events where theres not an end date so they won't be shown (Ongoing).
Is there a way of adding a fallback value to the "endDateTime"? I have tried the following:
var endDate = DateTime.Parse("31/12/3000 12:00:00 AM"); var liveFiltered = disruptions.Where(x => x.Value<DateTime>("startDateTime") <= DateTime.Now.Date) .Where(x => x.Value<DateTime>("endDateTime"), endDate >= DateTime.Now.Date);
But fails. Has anyone got any other suggestions?
Thanks
Hi Nathan.
Instead of hard coding the end date, you could try with DateTime.MaxValue.
Not sure whether it helps you, but it’s worth a try.
And the end where should probably look something like:
.Where(x => x.Value<DateTime>(“endDate”) ?? DateTime.MaxValue >= DateTime.Now)
Or something like that. :-)
Regards Malthe
Another helper method that can help:
var liveFiltered = disruptions.Where(x => x.HasValue("endDateTime"));
you can get all disruptions with end date and without.
Thanks,
Alex
Hi Malthe & Alex,
Thanks for your suggestions. Much appreciated.
Tried the DateTime.MaxValue but got : Operator '??' cannot be applied to operands of type 'DateTime' and 'bool'
Alex's solution worked but then I could not compare if the end date was greater than today.
I've added an extra checkbox to say if the event is ongoing and got it working using:
var liveFiltered = disruptions.Where(x => x.Value<DateTime>("startDateTime") <= DateTime.Now.Date) .Where(x => x.Value<DateTime>("endDateTime") >= DateTime.Now.Date || (x.Value<bool>("ongoing") == true));
Cheers
Nath
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Compare 2 dates with a fallback if null
Hi,
I have a disruption feed which displays disruptions happening now and disruptions happening in the future.
I have the live feed working like this:
but we have a few events where theres not an end date so they won't be shown (Ongoing).
Is there a way of adding a fallback value to the "endDateTime"? I have tried the following:
But fails. Has anyone got any other suggestions?
Thanks
Hi Nathan.
Instead of hard coding the end date, you could try with DateTime.MaxValue.
Not sure whether it helps you, but it’s worth a try.
And the end where should probably look something like:
Or something like that. :-)
Regards Malthe
Another helper method that can help:
you can get all disruptions with end date and without.
Thanks,
Alex
Hi Malthe & Alex,
Thanks for your suggestions. Much appreciated.
Tried the DateTime.MaxValue but got : Operator '??' cannot be applied to operands of type 'DateTime' and 'bool'
Alex's solution worked but then I could not compare if the end date was greater than today.
I've added an extra checkbox to say if the event is ongoing and got it working using:
Cheers
Nath
is working on a reply...