SQL-89 Date functions

mwpage

New Member
Can anyone help me with SQL-89 functions, I am looking for something that will return the current date (I know how to do this with SQL-92, but not SQL-89) also if there are any other available functions for SQL-89 any help with be great.

What I am trying to do is filter a SQL statement on a character field called TimeStamp, it is filled with a string that is a date formatted as YYYY-MM-DDThh:mm:ss, so in my query I want to return records
WHERE Timestamp BETWEEN 2011-09-09T00:00:00 and 2011-09-09T01:00:00 where those times are now, and one hour ago.

Any help would be great.
 

mwpage

New Member
I got a solution (it doesn't work exactly the way I want, but we were able to use it as a work-around) if someone has a better way please post it, or a list of functions available with the sql-89 driver, it seems like some embedded sql functions work, some with the {fn } syntax, some without, many don't work at all, even some of the sql-92 functions worked that way, but I couldn't find anything to consistently rely on,

anyways here is the function

WHERE Timestamp BETWEEN
{fn substring(string(today), 7, 4)} || '-' || {fn substring(string(today), 4, 2)} || '-' || {fn left(string(today), 2)} || 'T' || string(int(time / 60 / 60) - 1) || ':00:00'
AND
{fn substring(string(today), 7, 4)} || '-' || {fn substring(string(today), 4, 2)} || '-' || {fn left(string(today), 2)} || 'T' || string(int(time / 60 / 60) - 1) || ':59:59'

I converted today to a string first, then parsed out the month and date because if I used string(month(today)) it returned '9' and I needed '09' and I couldn't find a "RIGHT" function to work the way I would normally append '0's to the front of numbers.
Also when retriving the hour, the INT function appears to round, so that's a gotcha, I couldn't find a truncate, or floor type function to work to get away from the rounding issue.

best of luck if you come accross a need like this!
-matt
 
Top