Skip to content
Advertisement

SQLITE: Return 5 most recent records today and format date/time

I have a Xamarin.Forms app which has a ListView. I would like to populate the ListView with the 5 most recent items where the date is today’s date. If there are less than 5 items, the ListView should only display a row for each item (for example, if there is only one item, the ListView should only have one row).

I would then like to convert the date format to mm/dd/yyyy (as opposed to dd/mm/yyyy) and to change the time to 12-hour format. Is this possible?

The issue I have is: The name 'x' does not exist in the current context for this part of the statement: Where(x.ProductDateTime.Date == DateTime.Today). I am unable to retrieve the most recent records.

How can I retrieve the 5 most recent records with today’s date – and then format the result (in mm/dd/yyyy and 12-hour format)?

Advertisement

Answer

modify your query like this

to change the date format use a StringFormat

see here for a list of available date format strings supported in .NET

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement