Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases Reporting with SQL Date and Time Functions Practice Session

Jonatan Spahn
Jonatan Spahn
6,362 Points

SQL Stage 4: Practice problem.

So it asks to

-- Format dates in all the loans table in the UK format without the year. For example, April 1st is 01/04.

This is my code:

SELECT *, STRFTIME("%d/%m", "loaned_on") AS UK_format FROM loans;

but is there away to use STRFTIME and change the loaned_on and the return_by columns all in the UK format or do you have to do each one separate?

3 Answers

Steven Parker
Steven Parker
229,005 Points

STRFTIME operates on one timestring.

So you would need to use it on each column that you want to format separately.

Also, you don't need quotes around the column name.

Samandar Mirzayev
Samandar Mirzayev
11,834 Points

SELECT id,book_id,patron_id,STRFTIME("%d/%m", "loaned_on") AS "UK date loaned", STRFTIME("%d/%m","return_by") AS "UK date return by", STRFTIME("%d/%m","returned_on") AS "UK date return" FROM loans;

Jaron Trotter
Jaron Trotter
11,472 Points

SELECT *, STRFTIME("%d/%m") AS UK_format FROM loans;