Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting month from date using Linq

Status
Not open for further replies.

princesszea

Technical User
Aug 11, 2008
33
0
0
GB
Hi,

I need help extracting the month from my date column. The date is returned in this format 2012-07-06.

what I would like to do is filter the date based on the month only so return all the data for July etc.

This is what I have
Code:
          string value = HttpContext.Current.Session["Value "].ToString();
            string Month = "";
            if (value == "1")
            {
                
                Month = "July";
            }
            else 
                 
                Month ="August";
                
                 var query = from row in dt.AsEnumerable()
                                  where row by row.["Date_Column"] == Month ; <--- Also not sure to use this
                                  where ((row.Field<string>("Date_Column") == Month)) <--or this

Thanks in advance
 
try this:
Code:
     var query = from row in dt.AsEnumerable()
          where row.Field<DateTime>("Date_Column").Month.ToString().Equals(Month) ;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top