Ask Your Question
0

Want EXTRACT to return a 2-digit month in concatenation

asked 2020-03-06 01:11:30 +0200

bbater gravatar image

E.g.: EXTRACT (YEAR from "EventDate") || '-' || EXTRACT (MONTH from "EventDate") "YearMonth" ... ORDER BY "YearMonth" This gives incorrect order, e.g.: 2018-10 2018-3 2019-4 Wanted: 2018-03 2018-10 2019-04 I expect the solution is simple but I cannot fathom it from the Firebird manual. All help gratefully received.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2020-03-06 01:21:40 +0200

Ratslinger gravatar image

Hello,

This should work:

Select Extract(YEAR from "EventDate") || '-' || RIGHT('0' || trim(EXTRACT(MONTH from "EventDate")), 2) "YearMonth" from "YOUR_TABLE_NAME" Order by "YearMonth"
edit flag offensive delete link more

Comments

Ratslinger, once again to the rescue. It works! Great! Thank you!

bbater gravatar imagebbater ( 2020-03-06 03:14:17 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-03-06 01:11:30 +0200

Seen: 22 times

Last updated: Mar 06