-2

I need to get "Models.date_time" and execute "Foreach" for different days

Models.date_time {
2020-04-19 14:55:44

2020-04-19 16:55:44

2020-04-20 8:55:44

2020-04-19 12:55:44 }

foreach (var TransactionsModelsSaleDate in Models.Select(x => X.date_time.ToShortDateString()).Distinct()) {

DateTime TestUtcBeginDate = DateTime.ParseExact(TransactionsModelsSaleDate, "yyyy/MM/dd/00/00", System.Globalization.CultureInfo.CurrentCulture);
DateTime  BeginDate = ...............
DateTime  EndDate   = ...............

                    }

But I need to format "TransactionsModelsSaleDate" to get BeginDate , EndDate.

TransactionsModelsSaleDate {


2020-04-19

2020-04-20  }


But I also need to get this information

BeginDate  => 

2020-04-19 AM 12:00 00 

2020-04-20 AM 12:00 00 


EndDate    =>

2020-04-19  23:59 00

2020-04-20  23:59 00

How can I do?

Thanke so much!!

mjwills
  • 23,389
  • 6
  • 40
  • 63
JunJia Huang
  • 119
  • 9
  • 2
    I'm finding it very hard to understand your question. You've dumped a bunch of data in here, but with no explanation of what type it is, what you're trying to achieve etc. Please read https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/ – Jon Skeet Apr 21 '20 at 07:02
  • 1
    In addition to what Jon wrote, You should know that [DateTime have no format.](https://zoharpeled.wordpress.com/2019/12/19/for-the-1024-time-datetime-has-no-format/) In .Net, It is stored as the number of ticks since January 1st, 0001 at midnight. – Zohar Peled Apr 21 '20 at 07:08

1 Answers1

1

if you need list of dates you can select date part form DateTime

var list = Models.Select(x => X.date_time.Date).Distinct();

foreach (var TransactionsModelsSaleDate in list) {
}
Radik
  • 2,715
  • 1
  • 19
  • 24