# Date parameters problem

I have come from MS Office Access for over 15 years, and want to use dBase now in linux.

I have tried various solutions for other people on other boards and youtube: Between #date1# and #date 2# 'Between date1 and date 2' Between +date1 + and + date2+ "between" 'date1 "and" date2'

I either get no results, or every date, depending on which one of the above I use.

In Access it is Between #date1# and #date2#, but using that in dBase gives no results.

edit retag close merge delete

I stumble over terse SQL syntax errors a lot. So many poor and lacking error messages. This is especially frustrating to me because I have written a good language parser with careful error messages. It can work better. But the terse SQL error messages are what we have at the moment. SO, I think the best way to proceed is to break down your SQL into smaller parts, so you can divide and conquer. Take the SQL parts and poke them into the Menu, Tools, SQL... window, until you get it to work.

( 2017-05-02 06:01:01 +0200 )edit

@Awy65, In the table design, is your ReadingDate field of type Date?

( 2017-05-02 19:58:44 +0200 )edit

@Awy65, Also, by 'dBase' do you mean this or are you just referring to your HSQLDB database?

( 2017-05-02 20:23:58 +0200 )edit

No, what happened was that I had almost 200 tables to copy across from Access to dBase and queries, and I just let or assumed dBase would set the fields to the correct data type, but it didn't, and now it looks like I am having to change over 5000 dates to the Date type., unless there is an easier way of doing it.

( 2017-05-02 20:40:20 +0200 )edit

@Avy65, Ok, good to know what was wrong. There might be a way to convert the date string into a date type w/ a query and a function to convert to a date.

( 2017-05-04 17:45:59 +0200 )edit

Sort by » oldest newest most voted

You don't specify but I'll guess your talking about a query or some other SQL statement. Just tested with dBase sample file:

SELECT "dbase_f5".DATE
FROM "dbase_f5"
WHERE DATE between '1950-01-01' And '1970-01-01'


works without a problem. The # you mention is specific to the JET engine.

Edit 5/3/2017:

By using the term dBase I was off on a wild goose chase. I was doing all my tests based upon you being connected directly to a dBase file. It was a waste of many hours since I could have easily answered this with the correct information. I have a converted file for you already.

The attached is your table with an added field at the end named "NewReadingDate". This is now an actual date field. I also included "Query2" which is a simple query to use the select between clause.

Updated table: Result.odb

Edit:

I didn't include the "How" because it seems you do not have a grasp on SQL (please learn as this is essential in using ANY database). But here is what I did.

I did a 'quick & dirty' if you will, by creating a Temp table with your table selecting the record "ID and a re-format of the date in the text field:

SELECT "ID1", SUBSTRING("ReadingDate",7,4) || '-' || SUBSTRING("ReadingDate",4,2) || '-' || SUBSTRING("ReadingDate",1,2) MYDATE from "TestTable"


Next I add the new "Date" field to the existing table.

Finally, I updated the new field from the one generated in the temp table:

UPDATE "TestTable" SET "NewReadingDate" = (SELECT MYDATE FROM "TempTable" WHERE "TestTable"."ID1" = "TempTable"."ID1")

As for the checkmark:

Also, the ^ is an Upvote indicating approval of a question or answer & the down caret is dis-approval. The check mark signifies the correct answer was given.

Edit - UK format sample - ModifiedResult.odb

more

Update: @Awy65, I'm trying to understand your using a slash style date. In the table design, is your ReadingDate field of type Date or is it something else? For example here the field named created is of type Date: But it also quite possible to put a date string in a text field. It is easier to work with in a date field, but if it's in a text field that matters here.

LO can connect to a number of different data bases, and each one has somewhat different SQL. On top of that date formats can depend on where you live or work.

Rather than solve your problem for you, which I find counterproductive in the long run, I'd rather give you the tools to solve it yourself. So if you're connecting to the default embedded database which is HSQLDB1.8 the manual is here. There is a whole big section on dates and times in it. I also maintain a list of hopefully helpful resource links here.

I started w/ HSQLDB but now generally connect to MariaDB instead. I've found that this MySQL twin offers more features, and LO still works fine with it. LO is switching to Firebird as the default embedded database engine, so you might want to start look at that as well. (HSQLDB will remain as well.)

I worked with Access for many years before coming to LO, so welcome. I understand and appreciate how frustrating it can be to start over. This Q/A site has been quite helpful to me, and in particular Ratslinger and several others have been very helpful.

LO won't do everything that Access does, but it does do quite a bit, and it seems like development is slowly ongoing on it.

more

C:\fakepath\Copybase.odbYes it is a query with over 5000 records, and I want to select between 2 date ranges each month.

Thanks, but when I used this: SELECT "ReadingDate".DATE FROM "tblWXdataLeeds" WHERE DATE between '01-04-2017' And '30-04-2017

I get a syntax error with nothing to say where it is exactly. I added it underneath the existing SQL of the query

The ReadingDate is a heading with a list of dates in the column, and the tblWXdataLeeds is just that, a table

For the moment, there are too many things against me to learn SQL now and apart from LO dbase crashing on me every time I have made a change to one of the forms or queries, I thank you for the help you have given so far, but SQL is a world I am not familiar with, so I'll go back to Access for the time being.

I have put this into a SQL command in LO SELECT "tblWXdataleeds"."ReadingDate" From "tblWXdataLeeds" WHERE "ReadingDate" between '2017-04-01' And '2017-04-30' The status is: 2: Column not found: tblWXdataleeds.ReadingDate in statement [SELECT "tblWXdataleeds"."ReadingDate" FROM "tblWXdataLeeds" WHERE "ReadingDate" BETWEEN '2017-04-01' AND '2017-04-30']

But if I use this: SELECT "ReadingDate" From "tblWXdataLeeds" WHERE "ReadingDate" between '2017-04-01' And '2017-04-30'

The status is 1: Command successfully executed.

So now I have to figure out where to put that line into the existing SQL for the query.

Ok, I have just tried this: SELECT "WXdataleeds"."ReadingDate" From "tblWXdataLeeds" between '2017-04-01' And '2017-04-30', and still getting the syntax error message. The dates in the table are of the UK format ie: 01/04/2017

Apologies for the formatting of my replies, and hope this makes it more readable.

I have copied the existing SQL from the said query to make it more readable for me:

SELECT DISTINCT "ID1" AS "ID1", "ReadingDate" AS "ReadingDate", "TempMaxC" AS "TempMaxC", "TempWindChillC" AS "TempWindChillC", "TempMinC" AS "TempMinC", "RainFall" AS "RainFall", "Pressure" AS "Pressure", "RH" AS "RH", "WindGust" AS "WindGust", "WindSpeed" AS "WindSpeed", "Direct" AS "Direct", "CloudAmnt" AS "CloudAmnt", "CloudType" AS "CloudType", "Conditions" AS "Conditions"

Then I added the WHERE clause WHERE "ReadingDate" between '01/04/2017' And '30/04/2017' FROM "tblWXdataLeeds"

That returned this status error: 1: Unexpected token WHERE, requires FROM in statement Do I need to use another FROM, or have I put the WHERE clause in the wrong place.

This on it's own doesn't give what I want, as it for now just gives all the dates in the ReadingDate column, over 5000 of them SELECT "tblWXdataLeeds"."ReadingDate" FROM "tblWXdataLeeds" WHERE "ReadingDate" BETWEEN '01/04/2017' AND '30/04/2017'

Ok, I have now added the WHERE after FROM: FROM "tblWXdataLeeds" WHERE "ReadingDate" BETWEEN '01/04/2017' AND '30/04/2017' and that gives me every record, which I don't want

The reason for the AS is because that is how dbase built the query when it was created with the wizard, and I just copied and pasted it ...

more

Typically dates are stored in YYYY-MM-DD format. Your dates are in the wrong format. See sample in my answer.

( 2017-05-01 23:16:04 +0200 )edit

Also I don't understand your SQL. Select statement should be:

SELECT "YOUR-TABLE-NAME"."YOUR-FIELD-NAME" FROM "YOUR-TABLE" WHERE... and so on.

( 2017-05-01 23:20:17 +0200 )edit

Internal date format is what is needed. Your statement is still incorrect.

SELECT "tblWXdataleeds"."ReadingDate" From "tblWXdataLeeds" WHERE "ReadingDate" between '2017-04-01' And '2017-04-30'


For some reason you left our the WHERE & field to compare with and didn't put in the correct table name on the selected field.

( 2017-05-02 00:13:44 +0200 )edit

Just re-read your comment - "I added it underneath the existing SQL of the query". There is nothing to add. This is the entire statement. Except for the actual table & field names, it is identical to the code given in my answer. BTW, when a field or table name is all caps & no special characters, surrounding quotes are not needed as in the field DATE used in the answer.

( 2017-05-02 03:31:06 +0200 )edit

Unfortunately, the statement you posted is still not the one I have posted for you just above. You are still missing the WHERE "ReadingDate" portion which is what is generating the error. Sorry to hear about the crashing. More information would be needed to help on that problem.

( 2017-05-02 13:30:07 +0200 )edit

I am very sorry but I had a mis-spelling in my statement provided - tblWXdataleeds should have been tblWXdataLeeds. As you can see it is not necessary for your statement but is needed if other conflicting tables are also used. The SQL can be put in the Query section. Just select Create Query in SQL View, place the statement there & save it with a name.

( 2017-05-02 14:33:52 +0200 )edit

( 2017-05-02 14:34:48 +0200 )edit

Correct syntax for SELECT statement is SELECT...FROM...WHERE.... Yours is reversed. Also, you've done a lot of extra typing. If the result wanted is the same as the actual field name, you do not need to specify AS. "ReadingDate" will give the same exact result as "ReadingDate" AS "ReadingDate". If you wanted the output column title different, then AS is useful such as "ReadingDate" AS "Date". Here the output column name would be Date.

( 2017-05-02 17:02:00 +0200 )edit

You keep falling back to the date format problem. No matter what the display date is, the INTERNAL date is YYYY-MM-DD. This is a standard. Use BETWEEN '2017-04-01' AND '2017-04-30'.

( 2017-05-02 17:34:19 +0200 )edit

"to learn SQL now"? Truth is, access is based on SQL, just a different flavor. You see it when you go into edit a query and select SQL mode. I'm not going to fault you if you stick with the well known. But from my experience both Access and LO crash and misbehave at times, and about equally I would say. The one thing LO has over Access is our ability to report and get bugs fixed. There are still crashing bugs in my Access that have been there for years that MS hasn't bothered to fix.

( 2017-05-02 18:28:36 +0200 )edit