2

Current Code:

WHERE EXTRACT(YEAR_MONTH FROM timestamp_field) = EXTRACT(YEAR_MONTH FROM now())")

Instead of EXTRACT(YEAR_MONTH FROM now()), I want EXTRACT(YEAR FROM now()), but I want to hard code the month in. How do I go about concatenating the extract results with the MM month, for example 09.

I tried a few options below, with no luck.

(EXTRACT(YEAR FROM now())09)

CONCAT(EXTRACT(YEAR FROM now()), 09) 

'EXTRACT(YEAR FROM now())' + '09'

1 Answer 1

2

You almost had it:

SELECT CONCAT(EXTRACT(YEAR FROM now()), '09');

The "+" operator is not for string concatenation, unless you use Microsoft SQL Server.

In MySQL, use CONCAT() or if you set SQL mode to ANSI or PIPES_AS_CONCAT you can use the standard "||" operator:

SET SQL_MODE := 'ANSI';
SELECT EXTRACT(YEAR FROM now()) || '09';
Sign up to request clarification or add additional context in comments.

1 Comment

Doh... indeed.. Sooo close. Thanks Bill

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.