Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6846053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:34:33+00:00 2026-05-27T00:34:33+00:00

I want to build an expression for a Where clause Expression<Func<T, bool>> on a

  • 0

I want to build an expression for a Where clause

Expression<Func<T, bool>>

on a method that accepts a parameter of type

Expression<Func<T, DateTime>>

I want to manipulate my DateTime property to compare its internal properties like to add compare clauses to day, month and year properties.

My method is like the following:

public static class MyUtils
{
    public static Expression<Func<T, bool>> GetTime<T>(this Expression<Func<T, bool>> pExp, Expression<Func<T, DateTime>> MyProperty, int day, int month, int year)
    {
    }
}

I’d like to use it like this:

Expression<Func<MyClass, bool>> vExpression = p => false;
vExpression = vExpression.GetTime<MyClass>(c => c.MyDate, 21, 12, 2012);

So at the end of the method I have some comparisons between my “MyDate” property and the individual date values.

Can this be done?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:34:33+00:00Added an answer on May 27, 2026 at 12:34 am

    Perhaps something like this:

    static Expression<Func<T, bool>> GetTime<T>(
        Expression<Func<T, DateTime>> expression, 
        DateTime compare
    )
    {
        var comparison = Expression.Equal(expression.Body, Expression.Constant(compare));
        return Expression.Lambda<Func<T, bool>>(comparison, expression.Parameters);
    }
    

    You can then do:

    Expression<Func<MyClass, bool>> vExpression = GetTime<MyClass>(
        c => c.MyDate, 
        new DateTime(2012, 12, 21)
    );
    

    EDIT

    The above code shows how you can create a new expression tree based on the old one. You can create your new expression tree using any allowed constructs. Here is a slightly more complicated example:

    static Expression<Func<T, bool>> GetTime<T>(
        Expression<Func<T, DateTime>> expression, 
        DateTime compare
    )
    {
        var comparison = Expression.AndAlso(
            Expression.AndAlso(
                Expression.GreaterThanOrEqual(
                    Expression.Property(expression.Body, "Year"),
                    Expression.Constant(compare.Year)
                ),
    
                Expression.GreaterThanOrEqual(
                    Expression.Property(expression.Body, "Month"),
                    Expression.Constant(compare.Month)
                )
            ),
    
            Expression.GreaterThanOrEqual(
                Expression.Property(expression.Body, "Day"),
                Expression.Constant(compare.Day)
            )
        );
    
        return Expression.Lambda<Func<T, bool>>(comparison, expression.Parameters);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want build a sketch pad app on iPhone, I assume that this type
I want to build a Lambda Expression using Linq Expressions that is able to
I want to build a regex expression that allows me to parse through text
I want to build a bot that asks someone a few simple questions and
I want to build something like a network scanner, so that I see in
I want to build a System.Linq.Expression from the string List like this: System.Linq.Expressions.Expression x
I'm trying to build a list that will be used as the in clause
Expression<Func<Employee, bool>> employeeWhere = R => true; employeeWhere = R => R.PositionCode == M;
I need to build ONE regular expression that can detect ALL the following strings
I want to build a RegEx in JavaScript that matches a word but not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.