Tuesday, 17 May 2016

How To Remove Time From DateTime List Using Linq In C#.Net

5/17/2016 - By Pranav Singh 0

This article will show you how you can get only date from list containing datetime using linq in c#.net. This article will show How to remove time portion of date in C# in DateTime object only or How to get only Date from datetime.
So for this article first we will create a new console application and add the below code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        /// <summary>
        /// Get only date from list using linq in c#
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            List<DateTime> dateTime = new List<DateTime>();
            dateTime = GetDateList();
            var onlyDateList = dateTime.Select(m => m.Date.ToString("dd/MM/yyyy"));
            foreach(var item in onlyDateList)
            {
                Console.WriteLine(item + "\n");
            }
            Console.ReadLine();
        }
        public static List<DateTime> GetDateList()
        {
            List<DateTime> dateTime = new List<DateTime>();
            dateTime.Add(DateTime.Now.AddDays(1));
            dateTime.Add(DateTime.Now.AddDays(2));
            dateTime.Add(DateTime.Now.AddDays(3));
            return dateTime;
        }
    }
}

In above code I have prepared a list of datetime. Now I have applied linq query to remove time from the date.


About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top