Subject RE: [firebird-support] Formating date to yyyymmdd
Author Michel Veerman
Don't know of any special function for that. I believe the general
philosophy is that date conversions should be done in the client.



However, this will do the trick if you insist on doing the conversion in
the query. Although it doesn't look pretty :-)



select /* The year part, where I assume you never use years below 1000
:-) */

extract(year from current_date)

/* month part */

/* optional leading 0 */

|| case

when (extract(month from current_date) < 10)

then '0'

else ''

end

/* month value */

|| extract(month from current_date)

/* day part */

/* optional leading 0 */

|| case

when (extract(day from current_date) < 10)

then '0'

else ''

end

/* day value */

|| extract(day from current_date)

from my_table



Of course one could put this in a nice stored procedure as well, but
I'll leave that as an exercise for the user :-).



Kind regards,

Michel Veerman



Using Firebird 2.0, how can I format a date to yyyymmdd?

For example Jan 15 2009 -> 20090115

My first approach has been using EXTRACT(YEAR FROM BirthDate) ||
EXTRACT(MONTH FROM BirthDate) || EXTRACT(DAY FROM BirthDate)
but it does not work for me because I need to lead zeros and I cannot
find how do it. Maybe there is a direct function.

Thanks



[Non-text portions of this message have been removed]