-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!!

2
  • 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 codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question Commented Apr 21, 2020 at 7:02
  • 1
    In addition to what Jon wrote, You should know that DateTime have no format. In .Net, It is stored as the number of ticks since January 1st, 0001 at midnight. Commented Apr 21, 2020 at 7:08

1 Answer 1

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) {
}
Sign up to request clarification or add additional context in comments.

3 Comments

This is the method I need!
But I need to convert (2020-04-19) date to 2020-04-19-00-00
you can use custom format as DateTime.Now.ToString("yyyy-MM-dd-HH-mm") learn.microsoft.com/en-us/dotnet/standard/base-types/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.