Hi, I'm sorry but H2 does not support the syntax "INTERVAL 7 DAY". So even if you could create the DATE_ADD function, it still wouldn't work. As a workaround, you can use TIMESTAMPADD. This function is already supported in H2, and works the same way as in MySQL:
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timestampadd Regards, Thomas On Wed, Apr 25, 2012 at 8:47 AM, Oded Arbel <[email protected]> wrote: > Hi Guys. > > I'm trying to use H2 embedded in the Java application to run some code > that was written with MySQL in mind. Specifically it is using MySQL's > DATE_ADD function a lot. > > I though I can just write something that works like DATE_ADD and load > it into the database (changing the code is not really an option). So I > created a class: > > package com.taboola.h2; > > public class Functions { > public static java.sql.Date dateAdd(java.sql.Date originalDate, > String interval) { > java.sql.Date out; > // .. do something > return out; > } > } > > I then execute this when I set up the database: > Statement s = connection.createStatement(); > st.executeUpdate("CREATE ALIAS DATE_ADD FOR > \"com.taboola.h2.Functions.dateAdd\""); > st.close(); > > The above code executes without errors, but when I go and execute the > SQL code, it still fails with the error that DATE_ADD is not a > recognized function. > > Some sample SQL is this code to check for users that have logged in > recently: > SELECT * FROM apps.user_login_log WHERE NOW() <= > DATE_ADD(last_login_time, INTERVAL 7 DAY) ORDER BY last_login_time > > What am I doing wrong here? > > -- > You received this message because you are subscribed to the Google Groups "H2 > Database" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/h2-database?hl=en. > -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.
