Hi,
First of all, ill paste my bit of code and give an explanation of what im trying to accomplish and hope that you can help.
ETLSDataContext CT = new ETLSDataContext();
var t = from f in CT.Dates
select new
{
f.Date1
};
dataGridView1.DataSource = t;
dataGridView1.Columns.Add("D", "DateNow");
dataGridView1.Columns.Add("E", "DateDifference");
I have a SQL table with just Date1 in and use linq to pull it up
and the code i supplied shows me adding 2 other columns which are datenow and datedifference.
I need it so whenever the program loads it automatically populates the datagridview column "Datenow" with todays date and from there do some kind of a datediff query like
select datediff(Day, date1, datenow) as datedifference
I've been trying to do this all day and cannot come up with a solution and figured id ask the brain boxes.
Thanks for your time and patience.
Anthony
Loading
Guest UserPosted Dec 8, 2010, 11:48 AM
select new
{
f.Date1,
DateNow = DateTime.Today,
DateDifference = SqlMethods.DateDiffDay(f.Date1, DateTime.Today)
};
To be honest, I'm not very familiar with Linq, but something along those lines should accomplish what you're after.
Anthony ClarkePosted Dec 8, 2010, 11:50 AM
Anthony ClarkePosted Dec 8, 2010, 11:29 AM
Date1 DateNow DateDiff
Ill mark your answer as right then if you can give me the right syntax because im struggling.
SQL - select *, datediff(day, date1, getdate() as DaysEntered from date
Thanks alot for your help, ive marked it as correct :-)
Anthony
Guest UserPosted Dec 8, 2010, 11:23 AM
GETDATE() as DateNow
Please note that GETDATE() includes the current time as well.