Re: MySQL TO_DAYS() emulation in Derby

2006-09-18 Thread Lance J. Andersen
MySQL does support JDBC escape functions in their JDBC driver. Robert Enyedi wrote: Dan, I did not know of the JDBC escape functions. These work indeed with Derby, however the MySQL JDBC driver does not seem to support them (we need to run our queries on both Derby and MySQL). I know that

Re: MySQL TO_DAYS() emulation in Derby

2006-09-18 Thread Robert Enyedi
Dan, My timestamp computations were all local, but as mentioned in my previous post I managed to solve the issue. Regards, Robert Daniel John Debrunner wrote: Robert Enyedi wrote: This is exactly what I've been trying to do. The difficulty which I'm unable to overcome yet is that the ti

Re: MySQL TO_DAYS() emulation in Derby

2006-09-18 Thread Robert Enyedi
Donald, Thanks for the code snippet. This is also what I tried to do. However, a modification is required so that the timezone is explicitly set: Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); Otherwhise the miliseconds will be those from your own timezone (which most prob

Re: MySQL TO_DAYS() emulation in Derby

2006-09-18 Thread Robert Enyedi
Dan, I did not know of the JDBC escape functions. These work indeed with Derby, however the MySQL JDBC driver does not seem to support them (we need to run our queries on both Derby and MySQL). I know that this is not the best place to ask, but does anyone happen to know more about the statu

Re: MySQL TO_DAYS() emulation in Derby

2006-09-15 Thread dmclean62
Ok, then your best bet is probably to explicitly zero out the non-date parts: Calendar cal = Calendar.getInstance(); cal.setTime(yourDateObject); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Donald --

Re: MySQL TO_DAYS() emulation in Derby

2006-09-15 Thread Daniel John Debrunner
Robert Enyedi wrote: > This is exactly what I've been trying to do. The difficulty which I'm > unable to overcome yet is that the timestamp returned by > java.sql.Date.getTime() is not divisible with the number of miliseconds > in a day (24 * 60 * 60 * 1000). Yet when I create a java.util.Date() >

Re: MySQL TO_DAYS() emulation in Derby

2006-09-15 Thread Daniel John Debrunner
Robert Enyedi wrote: > Michael, > > As far as I know, year 0 in MySQL is actually 1 AD. However, it doesn't > necessarily matter when that year is when you have the comparability of > the results. > > What matters that this function in combination with its reverse, > FROM_DAYS, allows easily for

Re: MySQL TO_DAYS() emulation in Derby

2006-09-15 Thread Robert Enyedi
This is exactly what I've been trying to do. The difficulty which I'm unable to overcome yet is that the timestamp returned by java.sql.Date.getTime() is not divisible with the number of miliseconds in a day (24 * 60 * 60 * 1000). Yet when I create a java.util.Date() instance with that timestam

Re: MySQL TO_DAYS() emulation in Derby

2006-09-15 Thread dmclean62
Java calendar and date objects work in miliseconds but I think that fields marked as "date" rather than timestamp just have their hour/minute/second parts set to 0. Even so, it's fairly easy to roll a timestamp back to 00:00:00. You can then subtract the Date.getTime() values and divide by 86,40

Re: MySQL TO_DAYS() emulation in Derby

2006-09-15 Thread Robert Enyedi
Michael, As far as I know, year 0 in MySQL is actually 1 AD. However, it doesn't necessarily matter when that year is when you have the comparability of the results. What matters that this function in combination with its reverse, FROM_DAYS, allows easily for one to compute things like: - a

Re: MySQL TO_DAYS() emulation in Derby

2006-09-15 Thread Michael Segel
On Friday 15 September 2006 7:15 am, Robert Enyedi wrote: > The TO_DAYS() function returns the number of days since year 0. Did > someone successfully port this functionality to Derby? Constructing a > Java function for this is not as straightforward as it looks. > > Regards, > Robert Why? When wa

MySQL TO_DAYS() emulation in Derby

2006-09-15 Thread Robert Enyedi
The TO_DAYS() function returns the number of days since year 0. Did someone successfully port this functionality to Derby? Constructing a Java function for this is not as straightforward as it looks. Regards, Robert