0

I searched a lot and cannot find my answer. I'm trying to include 2 variable in my like statement to match a date that wasn't formatted correctly in a database I'm working on.

I need to:

Select count(*) as ABC 
    from database 
    where active like '1' 
        and agent = '$Employeestringid' 
        AND time LIKE '%$FilterMonth_%_$queryyear'"

The part that is currently not working is: '%$FilterMonth_%_$queryyear'

I need it to work and match a date formatted like: '9:10:31 PM Fri, May 20th 2016' by only capturing MONTH and YEAR.

1
  • Why not just part out the time to the two values being passed in and do an equality check? Consider and year(time) = $Queryyear and month(time) = $FilterMonth Doc Date Functions Commented Jun 1, 2016 at 19:03

2 Answers 2

1

When interpolating your variables in the string, PHP reads the _ as part of the variable name.

You need to use {} to prevent this behavior:

$query = "Select count(*) as ABC 
    from database 
    where active like '1' 
        and agent = '$Employeestringid' 
        AND time LIKE '%{$FilterMonth}_%_{$queryyear}'";
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome! This worked - thank you very much for your quick help Rocket :)
0

Remove the underscores

'%$FilterMonth%$queryyear'

2 Comments

Thanks Mojtaba - The recommendation that I received from Rocket worked in my code :) Problem solved.
@SiREKT. Glad to hear that. So, please mark it as solved

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.