❔ How to split dates?
I have following:
I added example dataSet to show my issue
ok, period in that dataSet will be this:
01.01.2023 0:00:00 - 16.02.2023 0:00:00
but I want another result
what I want:
18 Replies
how can I split array of datetime in that way?
Its a bit unsure what you actually want, the sample code you posted isn't valid syntax.
that last line isn't valid, as you can't index a datetime
what exactly do you want to get from
dateTime
here?
looks like you want your array to be a range between 01.01.2023 and 01.01.2023+47 days?
is that correct?would something like this work?
here is the method used
yes, my mistake
dArr[0] = dateTime;
but anyway I have another problem
I wanna split this range by monththis range being the given date + 47 days?
and you'd like it "split" by month, so divided into 2-3 lists of dates?
ah.. it was simple
there you go,
byMonth
is now a IEnumerable<List<DateOnly>>
okey thanks for solution! I appreciate you
if you need to know the month at a group level, you can just skip the select
you'll get an
IEnumerable<IGrouping<int, DateOnly>>
insteadthanks
I have another maybe stupid question
I added model and try to use it
I'd like to split operators if date was splitted..
how can I do it?
just for my understanding, is it really a good idea to have
Operator
be a class
here? Wouldn't record
be the best here?I personally greatly prefer records for things like this.
I've never used record. Why do I need it?
awesome, glad I noticed it. Pretty new to the whole
class vs struct vs record class vs record struct
deciding 😄
@Pobiega actually we could have Operator
and Department
be structs and have FakeBusinessModel
be a record class? Makes most sense to me but as I've said I'm new to this
you don't "need" records, you can create every type as a class
wihout issues. But it may have benefits to use record
instead in certain circumstances just like you may benefit from choosing a struct
over a class
in certain circumstances.I rarely use structs, unless I'm dealing with things that actually need to be structs, like for networking etc
tends to fall into the category of overoptimization
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.