Subject RE: [firebird-support] How do I convert a timestamp to a string from within a stored procedure?
Author Svein Erling Tysvær
Hi Michael!

You didn't ask, but there are a couple of things in your procedure that makes me wonder whether it is actually what you want (sorted in order of importance):

> ELSE IF ((iHour > 0) AND (iHour < 11)) THEN
> sHour = '0' || iHour;

Probably you want iHour < 10 rather than 11?

> IF (iHour > 12) THEN
> iHour = (iHour-12);

This basically means that you will be unable to differentiate between AM and PM and you cannot tell which of two timestamps come first (don't you care whether one entry is 6am or 6pm?).

> STR_TIMESTAMP = sMonth || sDay || sYear || sHour || sMinute || sSecond;

This will work OK as long as your application is local and you'll never have to sort or search depending on STR_TIMESTAMP. Internationally, several countries generally use DMY rather than MDY format, and if you avoid both of these and use YMD format, you also get a format that is easy to use for sorting and searching (well, not if you use a 12 hour clock).