skip to Main Content

enter image description here

I have 2 parameters. one is defaultFromD and another is defaualtToD. if I give 2 date range for this x.CreatedOn >= defaultFromD && x.CreatedOn <= defaultToD

x.CreatedOn >= ‘2021-10-17’ && x.CreatedOn <= ‘2021-10-20’

its working. but if I give same date for this two parameters this condition is not working.

x.CreatedOn >= ‘2021-10-20’ && x.CreatedOn <= ‘2021-10-20’

I want to knw how to pass this 2 logic in one condition. Please help me to resolve this issue.

Thank you…

  public ResponseDTO<IQueryable<LabRequestForLabOrderDTO>> GetApprovedLabRequestsQueryable(DateTime defaultFromD, DateTime defaultToD)
    {
        var resp = ResponseBuilder.Build<IQueryable<LabRequestForLabOrderDTO>>();
        var reqs = this.labRequestRepository.GetAllActive().Where(x => x.IsActive && x.TrxStatus == 1 && x.InvoiceStatus == "Approved"
                        && x.CreatedOn >= defaultFromD && x.CreatedOn <= defaultToD)
                .Select(x => new LabRequestForLabOrderDTO
                {
                    Clinic = x.Clinic,
                    LabOrderCreated = x.LabOrderCreated,
                    InvoiceStatus = x.InvoiceStatus,
                    CreatedOn = x.CreatedOn
                }).AsQueryable();

        resp.AddSuccessResult(reqs);
        return resp;
    }

3

Answers


  1. Chosen as BEST ANSWER

    This work for me

    var todate = defaultToD.AddDays(1);
    
    x.CreatedOn >= defaultFromD && x.CreatedOn <= todate
    

  2. This is due to DateTime and Date Formate.

    You should try the following way.

    Consider you column CreatedOn datatype is: DateTime

    x.CreatedOn.Date >= '2021-10-20' && x.CreatedOn.Date <= '2021-10-20'
    
    Login or Signup to reply.
  3. Try this

    x.CreatedOn.AddDays(-1) > defaultFromD && x.CreatedOn.AddDays(1) < defaultToD
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search