|
| Linq Query Question, should be simple I suppose... |
 |
Wed, 2 Apr 2008 14:37:28 +0000 |
Hi All,
I need the query below to only get data from a the current month. There is a
OpenedOn datefield but how do I parse this out and query based on it??? This is
what I have so far, not much but something.
Thanks in advance!!!
Tim
//So in this Query you can see I need to parse out the Date_Open field and the
Datetime.Now method. This is what I need help on, thanks again.
Int32 AssignedCount = usapp.Telmastes.Where(x => x.SENT_TO == SeqPersonnel
&& x.DATE_OPEN = DateTime.Now.Month).Select(x =>
x.Sequence).Count();
|
| Post Reply
|
| Re: Linq Query Question, should be simple I suppose... |
 |
Wed, 2 Apr 2008 15:06:12 +0000 |
If the DATE_OPEN field is a DateTime field, then can't you simply check the
month like so?
x.DATE_OPEN.Month == DateTime.Now.Month
I haven't tried this so it might blow up in your face.
|
| Post Reply
|
| Re: Linq Query Question, should be simple I suppose... |
 |
Wed, 2 Apr 2008 15:19:51 +0000 |
This is what I have and I get a "Input string was not in a correct
format." Any ideas?
USAPPDataContext usapp = newUSAPPDataContext();
string CurrentMonth = String.Format("{0:MMMM}", DateTime.Now );
string CurrentYear = String.Format("{0:yyyy}", DateTime.Now );
//Assigned Ticket Count
Int32 OpenCount = usapp.Telmastes.Where(x => x.OPEN_BY == SeqPersonnel
&& x.DATE_OPEN.Month.Equals(CurrentMonth) &&
x.DATE_OPEN.Year.Equals(CurrentYear)).Select(x => x.SEQUENCE).Count();
|
| Post Reply
|
| Re: Linq Query Question, should be simple I suppose... |
 |
Wed, 2 Apr 2008 15:26:32 +0000 |
Thanks Ed! I adjusted what I had to what you put down and tada....here is the
finished code.
Int32 OpenCount = usapp.Telmastes.Where(x => x.OPEN_BY == SeqPersonnel
&& x.DATE_OPEN.Month.Equals(DateTime.Now.Month) &&
x.DATE_OPEN.Year.Equals(DateTime.Now.Year)).Select(x =>
x.SEQUENCE).Count();
|
| Post Reply
|
| Re: Linq Query Question, should be simple I suppose... |
 |
Wed, 2 Apr 2008 17:20:44 +0000 |
Hey Ed, I have a slight modification I'm hoping you can help me out on, I don't
think it justifies a new post...anyways the answer before works great until you
query against a field that can be null. When it is null you get the error
below, I have tried working around it this way but no luck...do I have to
specifically change the value in the dbmapping layer, that doens't sound like a
good option. What is your thoughts...
CS1061: 'System.Nullable<System.DateTime>' does not contain a definition
for 'Month' and no extension method 'Month' accepting a first argument of type
'System.Nullable<System.DateTime>' could be found (are you missing a using
directive or an assembly reference?)var PersonnelClosed = from c in
usapp._GROUPDET_s
where c._GROUP_ == SeqGroup &&
c._PERSONNEL_.Telmastes_ClosedBy != null
select c;
i = 0;
Int32 GroupClosedCount = 0;foreach (_GROUPDET_ c in PersonnelClosed)
{
SeqPersonnelForEach = c._MEMBER_;
GroupClosedCount = GroupClosedCount + usapp.Telmastes.Where(x =>
x.CLOSED_BY == SeqPersonnelForEach && x.CLOSED_ON != null &&
x.CLOSED_ON.Month.Equals(DateTime.Now.Month) &&
x.CLOSED_ON.Year.Equals(DateTime.Now.Year)).Select(x =>
x.SEQUENCE).Count();
i = i + 1;
}
GroupTicketCountOpened.Text = Convert.ToString(GroupClosedCount);
|
| Post Reply
|
|
|
|
|
|
|
|
|
|