0

The following query works fine when not using a variable for the date&time. However, I would like to use a variable for "2014-09-29 09:00:00".

    $query = '  SELECT *
                FROM dateTime1
                WHERE dateBooked="2014-09-29 09:00:00"';

(The "dateBooked" field is of datetime format.)

I below doesn't work:

$dateX = '2014-09-29 09:00:00';

$query = '  SELECT *
            FROM dateTime1
            WHERE dateBooked=' .$dateX;

2 Answers 2

2

You're missing quotes around your date:

$query = "  SELECT *
        FROM dateTime1
        WHERE dateBooked='" .$dateX . "'";

or

$query = "  SELECT *
        FROM dateTime1
        WHERE dateBooked='$dateX'";
Sign up to request clarification or add additional context in comments.

4 Comments

oh sure answer the easy ones, like you NEED the rep points ;)
Lol. I was too busy today to be active here. It felt good to just to give an answer.
after 100k you should not be allowed to answer questions that don't require 3 phD's P)
Beauty! fastest answer I've ever had :)
1

Try this:

$dateX = '2014-09-29 09:00:00';
$query = '  SELECT *
                        FROM dateTime1
                        WHERE dateBooked="' . $ dateX . '"';

Comments

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.