How can i check if DateTime having 0 hours 0 minutes and 0 second and update only time value in List<Dictionary<string, object>>
for specific key?
Done with normal For loop, but how can i do this with linq
Working code:
using System;
using System.Collections;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
var data = new List<Dictionary<string, object>>();
var d1 = new Dictionary<string, object>();
d1.Add("START", new DateTime(2019, 05, 12));
d1.Add("END", new DateTime(2019, 05, 14));
d1.Add("Room1", "Room1");
var d2 = new Dictionary<string, object>();
d2.Add("START", new DateTime(2019, 05, 12));
d2.Add("END", new DateTime(2019, 05, 14));
d2.Add("Room2", "Room2");
var d3 = new Dictionary<string, object>();
d3.Add("START", new DateTime(2019, 05, 12));
d3.Add("END", new DateTime(2019, 05, 14));
d3.Add("Room3", "Room3");
data.Add(d1);
data.Add(d2);
data.Add(d3);
if (data != null)
{
for (int i = 0; i < data.Count; i++)
{
DateTime dt = (DateTime)data[i]["END"];
Console.WriteLine("Before :" + data[i]["END"].ToString());
if (dt.Hour == 0 && dt.Minute == 0 && dt.Second == 0)
{
dt = dt.AddHours(23).AddMinutes(59).AddSeconds(59);
data[i]["END"] = dt;
}
Console.WriteLine("After :" + data[i]["END"].ToString());
}
}
}
}
OutPut as Below:
Before :5/14/2019 12:00:00 AM
After :5/14/2019 11:59:59 PM
Before :5/14/2019 12:00:00 AM
After :5/14/2019 11:59:59 PM
Before :5/14/2019 12:00:00 AM
After :5/14/2019 11:59:59 PM