![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2004
Posts: 17
Rep Power: 0
![]() |
vb with access DB: comparing dates
i want to generate a report that ranges from certain dates. example: from July 1 2005 to July 7 2005.
in access, the database field is named "LogDate" and the data type is "Date/Time" and I selected "Short Date" from the menu below. the format for this date is 7/1/2005, or m/d/yyyy. in VB 6, i used the SQL Statement: "SELECT * FROM TableName WHERE LogDate = " & Date if today is july 6, then it would show "SELECT * FROM TableName WHERE LogDate = 7/6/2005. i have records that are on july 6, but the program does not see it as if the statement was invalid. if i place 7/6/2005 in single quotes (ex. LogDate = '7/6/2005') it says data type mismatch. How do you compare dates in VB? what data type should i use in access as well as in VB? any suggestions? thanks... |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Try using this:
... WHERE LogDate = 2005-07-06 |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Nov 2004
Posts: 17
Rep Power: 0
![]() |
thanks,... ill try that
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: Nov 2004
Posts: 17
Rep Power: 0
![]() |
well... that suggestion didnt work. thanks though...
but i finally figured it out... and i thought i would share it with you.. references: http://www.ozzu.com/ftopic31951.html http://support.microsoft.com/default...b;en-us;296653 apparently, we have to use the "#" symbol instead of using/not using a single quote: variable = "SELECT * FROM TableName WHERE LogDate = #" & thedate & "#" SELECT * FROM TableName WHERE LogDate = #7/5/2005# |
|
|
|
|
|
#5 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Ah... the joys of Access. How lovely...
|
|
|
|
|
|
#6 |
|
Expert Programmer
|
Yeah that's your standard run of the mill VB Date literal. I'm suprised the long date didn't work though - how about epoque time?
|
|
|
|
|
|
#7 |
|
Newbie
Join Date: Nov 2004
Posts: 17
Rep Power: 0
![]() |
yeah long date didnt work. i tried all of them (i think) using the "FormatDateTime" function in vb. um... sorry i dont know what epoque time is...
...i want to edit the title... but i cant edit the thread title.. how do u do it? i want to add "date and time comparison" cause i have another question related to this... How do you get the number of hours in between 2 given time values that have different dates. i mean i want to get the number of hours, for example, between july 6 2005 10:00 PM and july 7, 2005 6:00 am. is there a function that computes this? i found 1 way but its not that perfect. any suggestions? its a login/logout thing and i have to compute the no of hrs he was logged in... |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Apr 2005
Posts: 6
Rep Power: 0
![]() |
hi you can compare date by using format(fieldname,"dd/mmm/yyy")
so in acces it will not confused between date and month so your query will be "where LogDate =#" & format(06/07/2005,"dd/mmm/yyyy") trythis out and reply me |
|
|
|
|
|
#9 | |
|
Expert Programmer
|
Quote:
NoOfHoursTillChristmas = DateDiff("h", Now, "25/12/2005") |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|