Date Format / SQL Query..

I have a nice problem with the date format in my Access DB and a SQL query.

First of all some code:

//(table1 = CDaoRecordset*)
CString sel_time;
sel_time = table1->date_field.Format("%Y-%m-%d%H:%M:%S");

CString SQL_select = "select * from [table_name] where (\"Last Updated\" > DateValue(#" ;
SQL_select += sel_time;
SQL_select += "#) )";

Hope there are no typos....

Anyway. The problem I have is that the result of my query is the  whole table "table_name" and not just the ones which have the correct date. As some of you might have guessed already the bug lies in the format of the date. My Access DB Date Format is "31.01.99" (good ol' european style).

Who paid attention and isn't confused (I am) and can help me before I go home and drink.

Thanks (cry for help......)
StapmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KangaRooCommented:
>> the bug lies in the format of the date. My Access DB Date Format is "31.01.99"
Doesn't matter to much, dates are internally stored 'correct'. That is only the display/entry format

What is the contents of sel_time?
Try a query like
  CString sql = "SELECT DateValue(#" ;
  sql += sel_time;
  sql += "#);
to review what is the result of the datevalue function.
0
KangaRooCommented:
Secondly, what are you doing? You get a field from one table, and use its value in the where clause of another query? Sounds like a JOIN to me.
0
StapmanAuthor Commented:
Content of sel_time is something like "1999-10-15 10:35:15". What I'm doing is following: I'm trying to get several datasets which have a certain date and insert these into a recordset. I open a recordset with the SQL query (SQL_select).
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

StapmanAuthor Commented:
By the way: I'm using VC++ 6.0 and in my "Variables" window the table with table_name (the one which is used for the query) has some interesting values. When I look at the table attribute "Last Updated"  has the value "36355.000000000". Is that the internal date format you mentioned??? All other values are "correct" i.e. look the same in Access.
0
StapmanAuthor Commented:
By the way: I'm using VC++ 6.0 and in my "Variables" window the table with table_name (the one which is used for the query) has some interesting values. When I look at the table attribute "Last Updated"  has the value "36355.000000000". Is that the internal date format you mentioned??? All other values are "correct" i.e. look the same in Access.
0
OlethrosCommented:
I had a similar problem using C++ Builder and Access97.
To solve the problem, I tested my queries directly in Access
and found a very interesting SQL date format. Here an example:

SELECT * FROM Blabla
WHERE date >= #12-24-98 09:00:00#

The displayed (country dependent) date format differs from the internal Access date format (float), and the SQL date format is
#mm-dd-yyyy hh:mm:ss#
Confusing, innit?

So you should build your date string with

sel_time = table1->date_field.Format("#%m-%d-%Y %H:%M:%S#");

Since i don't know much about Format(), I hope the hash marks are ok here...

But your SQL string looked a little strange (DateValue?!)
Perhaps you should try the following code:

CString SQL_select = "select * from [table_name] ";
SQL_select += "where [Last Updated] > ";
SQL_select += sel_time;

That should do the trick, but mind the spaces at the end of the strings! And don't try to put the date string between quotes, the
hash marks are all you need to limit the date string.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
StapmanAuthor Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.