I would like to get entries from the sql database between two specified dates. I am thinking of something like:
dim fromDate as new Date (2012, 4, 15)
dim toDate as new Date
dim rs as new RecordSet
// connection to database not specially mentioned here
rs = db.SQLSelect("select * from myTable where date > "+fromDate+" and date < "+toDate)
But that obviously doesn’t work. Does someone know how to select the specific db-entries?
Postgresql
Dim ps As PostgreSQLPreparedStatement = App.DB.Prepare(“select * from myTable where date >= $1 and date <= $2”)
dim rs as recordSet = ps.SQLSelect(fromDate.SQLDate, toDate.SQLDate)
A) That’s an error in your database. Dates should never be stored that way.
B) You’ll need to reformat the date in order to use it. You can use Substr() to pick out the contents and rearrange them.
Alright, thanks Tim. The dates come that way from an import from an accounting software via Excell. Where can I find out more on substr()? The docs don’t deliver any results.
[quote=249279:@Tim Hare]A) That’s an error in your database. Dates should never be stored that way.
B) You’ll need to reformat the date in order to use it. You can use Substr() to pick out the contents and rearrange them.[/quote]
But that shouldn’t be an excuse to import them that way. Your import routine should make an effort to convert whatever you throw at it into an SQL friendly date representation. Tim is dead on - dates should be dates in databases. Else you lose the possibility to do any meaningful operation on that field (search, order by).
Oh, I see. I just took the “julianday”-command from olivier without questioning what it does. Trying this command:
dim myDate as string = "2007-01-01"
"select * from accounting where SUBSTR(date,7,4) || '-' || SUBSTR(date,4,2) || '-' || SUBSTR(date,1,2) as cvDate > '"+myDate+"' as cvDate"