Subject Re: [firebird-support] How do I convert CURRENT_TIME and CURRENT_DATE to a string?
Author Alan.Davies@aldis-systems.co.uk
You could try this instead which works very well and is much simpler.
You need freeudflib and fudlib.

DECLARE VARIABLE tTime TIMESTAMP;
declare variable stime varchar(8);
<then somewhere in your procedure - where you want it>

stime= vlpad(f_fixedpoint(extracthour(:tTime ),0),'0',2)||':'||
vlpad(f_fixedpoint(extractminute(:tTime ),0),'0',2)||':'||
vlpad(f_fixedpoint(extractsecond(:tTime ),0),'0',2);

This will give e.g. 13:14:15 <I use ":" for client's formatting
requirements>
Remove " ||':' " and you get 131415

You can try it as a select statement to prove it works ok, like so:
select vlpad(f_fixedpoint(extracthour(current_time ),0),'0',2)||
vlpad(f_fixedpoint(extractminute(current_time ),0),'0',2)||
vlpad(f_fixedpoint(extractsecond(current_time ),0),'0',2)
from rdb$database

Hope this helps.

--
Alan J Davies
Aldis


Quoting SoftTech <miket@...>:

> Greetings All,
>
> I have the date conversion working but I am still having a little
> problem with the time conversion to HHMMSS format.
>
> Here is what I have so far and it is almost working unless the hour,
> minute or second portion is less than 10, in which case I need to
> insert a 0 before it.
>
> My issue is that there is no Length function to determine the length
> of a string (unless it is not called LENGTH())
>
> The area I need help with is commented out with /* */
>
> I also think this is a little messy so if anyone has any tips on how
> to clean it up I'm all ears..
>
> Thanks,
> Mike
>
> DECLARE VARIABLE tTime Time;
> DECLARE VARIABLE sTime VarChar(20);
> DECLARE VARIABLE sConvertedTime VarChar(6);
> DECLARE VARIABLE sChar Char(1);
> DECLARE VARIABLE sHours VarChar(2);
> DECLARE VARIABLE sMinutes VarChar(2);
> DECLARE VARIABLE sSeconds VarChar(2);
> DECLARE VARIABLE iTimeSepCount SmallInt;
>
>
> /* Convert the time to a string in the format HHMMSS*/
> tTime = CURRENT_TIME;
> sTime = tTime;
> sHours = '';
> sMinutes = '';
> sSeconds = '';
> sConvertedTime = '';
> iTimeSepCount = 0;
> WHILE (ISDONE = 0) DO
> BEGIN
> sChar = SUBSTRING(sTime FROM 1 FOR 1);
> IF (sChar = ' ') THEN
> ISDONE = 1;
>
> IF (sChar = ':') THEN
> BEGIN
> /* IF (iTimeSepCount = 0) THEN
> IF (LENGTH(sHours) < 1) THEN
> sHours = '0' || sHours;
> ELSE IF (iTimeSepCount = 1) THEN
> IF (LENGTH(sHours) < 1) THEN
> sMinutes = '0' || sMinutes;
> ELSE IF (iTimeSepCount = 1) THEN
> IF (LENGTH(sHours) < 1) THEN
> sSeconds = '0' || sSeconds; */
>
> iTimeSepCount = iTimeSepCount + 1;
> END
> ELSE
> BEGIN
> IF (iTimeSepCount = 0) THEN
> sHours = sHours || sChar;
> ELSE IF (iTimeSepCount = 1) THEN
> sMinutes = sMinutes || sChar;
> ELSE IF (iTimeSepCount = 2) THEN
> sSeconds = sSeconds || sChar;
> END
>
> sTime = SUBSTRING(sTime FROM 2);
> END
> sConvertedTime = sHours || sMinutes || sSeconds;
>
>
> [Non-text portions of this message have been removed]
>
>