Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 6th, 2005, 6:18 AM   #1
GoO
Newbie
 
Join Date: Nov 2004
Posts: 17
Rep Power: 0 GoO is on a distinguished road
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...
GoO is offline   Reply With Quote
Old Jul 6th, 2005, 9:31 AM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Try using this:
... WHERE LogDate = 2005-07-06
The international standard date format is YYYY-MM-DD - I believe that's the best way to do it. The code you used could be mistaken for D/M/YYYY instead of M/D/YYYY, which is why it would have returned nothing.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jul 6th, 2005, 6:02 PM   #3
GoO
Newbie
 
Join Date: Nov 2004
Posts: 17
Rep Power: 0 GoO is on a distinguished road
thanks,... ill try that
GoO is offline   Reply With Quote
Old Jul 7th, 2005, 8:05 AM   #4
GoO
Newbie
 
Join Date: Nov 2004
Posts: 17
Rep Power: 0 GoO is on a distinguished road
Smile

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 & "#"
in string form:

SELECT * FROM TableName WHERE LogDate = #7/5/2005#
GoO is offline   Reply With Quote
Old Jul 7th, 2005, 1:10 PM   #5
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Ah... the joys of Access. How lovely...
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jul 8th, 2005, 7:38 PM   #6
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
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?
Rory is offline   Reply With Quote
Old Jul 12th, 2005, 11:46 AM   #7
GoO
Newbie
 
Join Date: Nov 2004
Posts: 17
Rep Power: 0 GoO is on a distinguished road
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...
GoO is offline   Reply With Quote
Old Jul 15th, 2005, 11:33 PM   #8
John
Newbie
 
Join Date: Apr 2005
Posts: 6
Rep Power: 0 John is on a distinguished road
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
John is offline   Reply With Quote
Old Aug 1st, 2005, 2:16 PM   #9
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
Quote:
Originally Posted by GoO
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...
Try this:
NoOfHoursTillChristmas = DateDiff("h", Now, "25/12/2005")
Rory is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:49 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC