Subject Re: [firebird-support] How do I convert CURRENT_TIME and CURRENT_DATE to a string?
Author SoftTech
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]