Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can we use INTERVAL Keyword Dynamically ? 1

Status
Not open for further replies.

vpshriyan

IS-IT--Management
Jul 26, 2002
356
IN
I want to add 'n' number of minutes to a datetime field. Following code works fine in 4GL.

database rntdb
MAIN
DEFINE c_time DATETIME YEAR TO SECOND
LET c_time="2002-07-28 23:40:40"
DISPLAY c_time
LET c_time=c_time + INTERVAL(46) MINUTE TO MINUTE
DISPLAY c_time
END MAIN

Result:

2002-07-28 23:40:40
2002-07-29 00:26:40

To make this bit of code re-usable and make it dynamic by putting it in a function, results in a disaster. (compilation error)

FUNCTION add_minute(l_units)

DEFINE c_time DATETIME YEAR TO SECOND, l_units smallint
LET c_time="2002-07-28 23:40:40"
DISPLAY c_time
LET c_time=c_time + INTERVAL(l_units) MINUTE TO MINUTE
DISPLAY c_time

END FUNCTION

Compilation time error message:

Non-numeric character in datetime or interval.
See error number -1262.

Would anybody tell me how to solve my requirement using INTERVAL ?

thanks.
shriyan
 
Hi:

Unfortunately Informix 4GL doesn't allow you to change the scale of an interval type:

interval (46) minute to minute

bottom line: the "46" can't be a variable. I think a better solution is using the units keyword to add/subtract an amount to/from a datetime. The stub below adds 3 seconds, 3 minutes, and 3 hours to the current datetime.

Regards,

Ed


main
define dt datetime year to minute,
cnt smallint

let cnt = 3

let dt = current + cnt units second

let dt = current + cnt units minute

let dt = current + cnt units hour

end main
 
Hi Ed,

Thanks for the alternate solution. It serves my purpose.

Regards,
Shriyan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top