1

Okay, so say I'm using the CONCAT function, right?

So I have a date in a field called start_date. It looks like 2016-02-07.

Next, I subqueried that to do MONTH(start_date) AS start_month and YEAR(start_date) as start_year. Obviously, start_month would return 02 and start_year returns 2016.

Now lets say I wanted to combine those two so it says 02/2016. If I simply do:

CONCAT('start_month', '/', 'start_year') it returns start_month/start_year and if I do CONCAT(start_month, '/', start_year) it returns Error: CONCAT: The 1st argument has type int64 but expected type string or bytes.

So what am I doing wrong and how do I fix this? Additionally, is there an easy way I can convert the numerical months to their actual names (i.e. 02 becomes February)? If there isn't an easy way, its not a huge deal.

1 Answer 1

2

from question: Obviously, start_month would return 02 and start_year returns 2016.

Nope - they will return 2 and 2016 respectivelly and as integers not as strings - see more on MONTH() and/or Date and time functions

So you should cast month and year values to STRING

For example,
CONCAT(STRING(start_month), '/', STRING(start_year))

The better way to do this is as below

SELECT STRFTIME_UTC_USEC('2016-02-07', "%m-%Y")

see here for more details

is there an easy way I can convert the numerical months to their actual names (i.e. 02 becomes February)?

SELECT STRFTIME_UTC_USEC('2016-02-07', "%B")
Sign up to request clarification or add additional context in comments.

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.