yes I am. I had the query run without the 'and' conditions for the date and that is what was returned. The table is very small at the moment since we haven't installed to production yet.
Main Topics
Browse All Topicshi all,
I'm trying to run a query from VBA, which I will be moving to VB6 once it's installed on my work PC. basically I need to get some records between 2 dates.
the code works as far as getting the right date time for starting and ending. but when the query runs against the AS/400 I dont get anything back. below are some examples of what's being sent and what is in the database itself.
sending:
Start Date/Time: 2009-08-30-17:01:00.000000
End Date/Time: 2009-08-31-12:00:00.000000
Actual data from database: 2009-08-30-21.27.21.000000
both of which fall between the date/times sent.
I'm at a loss how to do this. I've never really worked with the AS/400 but have done a lot with sql server and the dreaded Access sql.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Well,
First of all, if I read this right, you are looking for records with a date that is less than or equal to your start time AND simultaneously greater than or equal to your end time. Unlikely you will find many dates that fit that test.
Second,
A timestamp contains three components: a DATE, a TIME, and microseconds.
Assuming CPTTST is defined on the AS/400 as a TIMESTAMP, you won't want to sue the date() function at all, since it just strips the date portion (year, month, day) out of a timestamp (year, month, day, hours, minute, second, microsecods)
If your goal is to use a date plus a time for your extract, then you just need to compare a properly formatted quoted string to the timestamp field.
- Gary Patterson
Check out my EE profile: http://www.experts-exchang
Also note that in and ISO timestamp, the separator in the time portion of the timestamp is "." (period), not ":" (colon). I get an error when I try to substitute colons on a native query on the AS/400,
- Gary Patterson
Check out my EE profile: http://www.experts-exchang
" And date(timestamp('" & NewStart_DateTime & "')) <= date(timestamp(CPTTST)) " & _
" And date(timestamp('" & NewEnd_DateTime & "')) >= date(timestamp(CPTTST)) " & _
states that the start time is less than the database field and the end date is greater than the database field.
Taking the date portion off of " And date(timestamp('" & NewEnd_DateTime & "'))" causes an error "SQL0180: Syntax of date, time or datestamp value not valid"
Hi Gary,
Looks like you read it wrong. :)
" And date(timestamp('" & NewStart_DateTime & "')) <= date(timestamp(CPTTST)) " & _
" And date(timestamp('" & NewEnd_DateTime & "')) >= date(timestamp(CPTTST)) " & _
Hi Hi whsrptq,
DB2 has some pretty power date manipulation routines (and syntax). There's no need to jump through all of these hoops when you don't have to. You don't have to build and pass an entire datetime only to recast it to a date. You can build the date and pass it. You can also set the range within the query instead of having to build and pass another date.
" And date('" & NewStart_Date & "') <= date(CPTTST) " & _
" And date('" & NewEnd_Date & "') >= date(CPTTST) " & _
or
" And '" & NewStart_Date & "' <= date(CPTTST) " & _
" And '" & NewEnd_Date & "' >= date(CPTTST) " & _
or even
" And date (CPTST) BETWEEN '" & NewStart_Date & " AND " & NewEnd_Date & "' _
I've probably misplaced a quote, but it's close. :)
Kent
DB2 is sooooo picky....
A datetime (at least on other flavors of DB2) has a period between the date and time portions, not a hyphen. That's what's causing the date-time error.
So a substr() of the first 10 characters will return '2009-08-30'. If your instance of DB2 is configured with that as the default date, perfect. If not, you'll need to format the date (in php) in the correct format, probably '2009/08/30' or '08/30/2009'.
Kent
Kent,
Yep, read it wrong. I prefer your BETWEEN syntax: much clearer to me.
whsrptq:
I think that the SQL0180 is because the syntax of your TIMESTAMP constant in the SQL is not correct:
NewStart_DateTime = Format(NewStart_DateTime, "yyyy-MM-dd-hh:mm:ss.00000
NewEnd
Swap the ":"s for "."s and see if that doesn't resolve the syntax error.
Do you want your selection criteria to include a date and time, or just a date? IF so, you need to drop those DATE() references and just compare the TIMESTAMP variable to a valid TIMESTAMP literal.
Again, how is
- Gary Patterson
Check out my EE profile: http://www.experts-exchang
HAH!
in typing an updated section to this, my original code was
NewStart_DateTime = Format(NewStart_DateTime, "yyyy-MM-dd-hh:mm:ss.00000
2009-0
the as 400 value was
2009-08-30-21.25.49.000000
the as/400 value has 1 less zero on the end. making the code read
NewStart_DateTime = Format(NewStart_DateTime, "yyyy-MM-dd-hh:mm:ss.00000
2009-08-30-17:01:00.000000
fixes the issue. OMG i never thought it would be THAT picky.
Seems inappropriate to delete the question when we solved:
Misuse of the date() function,
Syntax of the timestamp separators.
Not to mention that I also explained the three components of the timestamp field, including the MICROSECONDS field, which, by definition is 10^-6?
I'm fairly sure that Kent's explanation of how precise you need to be with the timestamp at least assisted you in your solution.
- Gary
Seems inappropriate to delete the question when we solved:
Misuse of the date() function,
Syntax of the timestamp separators.
Not to mention that I also explained the three components of the timestamp field, including the MICROSECONDS field, which, by definition is 10^-6?
I'm fairly sure that Kent's explanation of how precise you need to be with the timestamp at least assisted you in your solution.
- Gary
Business Accounts
Answer for Membership
by: KdoPosted on 2009-08-31 at 12:00:13ID: 25225356
Hi whsrptq,
The date portion of the query's filter looks reasonable. (It may be easier to read if you code it using BETWEEN, but that won't affect the results.)
Are you sure that the sample data that you show is being selected with a correct value for cptemp?
Kent