Wrox Programmer Forums
|
BOOK: Beginning VB.NET Databases
This is the forum to discuss the Wrox book Beginning VB.NET Databases by Thearon Willis; ISBN: 9780764568008
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning VB.NET Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 22nd, 2007, 07:07 AM
Authorized User
 
Join Date: Jan 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default DateDiff Question

Hello guys,

From the book I've been looking at comparing date/time values and currently I'm presented with a problem.

I have an application that processes and stores the time in an Access table. I use the Today() function so that 12:00 is prefixed to the time.

However the application also queries a given time value (on a form) against a specified time field in the table. The time value on the form of course doesn't contain the date so DateDiff doesn't work when comparing the minutes and seconds:

e.g.

'Compare minutes
Select.....where DateDiff("n",[datefieldintable], [timefieldonform]) = 0

'and compare minutes

Select.....where DateDiff("s",[datefieldintable], [timefieldonform]) = 0

So what I've worked out is that my time form has to have the date appended to the time and the word 'am' appended to it for the query to work. To get the table date/time field's date I've attempted to use the Datepart() function to pull out the dd, mm, and yyyy, append the time and then the word's "am". Here's what I've got so far:

"DateDiff('n'," & strdtfield & ", #" & _
"DatePart('d'," & strdtfield & ")&""/""&" & _
"DatePart('m'," & strdtfield & ")&""/""&" & _
"DatePart('yyyy'," & strdtfield & ") " & _
"12:" & txtfldTime.Text & "am#) = 0")

Here's the SQL string output:

SELECT * FROM [CrewMembers] LEFT JOIN [FitnessTestHistory] ON [CrewMembers].[CrewMemberID] = [FitnessTestHistory].[CrewMemberID] WHERE (DateDiff('n',[FitnessTestHistory].[AbdominalHold], #DatePart('d',[FitnessTestHistory].[AbdominalHold])&"/"&DatePart('m',[FitnessTestHistory].[AbdominalHold])&"/"&DatePart('yyyy',[FitnessTestHistory].[AbdominalHold]) 12:00:00am#) = 0) ORDER BY [FitnessTestHistory].[AbdominalHold]

Here's the error I'm getting

"Syntax error in date in query expression"

Can someone help me correct the date part of the string please? Thanks.
 
Old August 25th, 2007, 05:12 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

It looks like there needs to be a space in your time. For example, you have "12:00:00am" and I believe it needs to be "12:00:00 am".

If that does not work, could you post two dates and times that you are trying to compare? Also a sample of the date and time values as it appears in your database would be helpful.

Thearon
 
Old August 25th, 2007, 10:11 PM
Authorized User
 
Join Date: Jan 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Thearon,

That was the answer. I didn't have a space between the "00" and the "am".

Thanks for your help.

ExDb






Similar Threads
Thread Thread Starter Forum Replies Last Post
DateDiff zahyea .NET Framework 1.x 0 October 16th, 2007 04:38 AM
How to get Milliseconds from DateDiff ? ashu_from_india Pro VB 6 2 July 5th, 2007 03:27 AM
datediff ebburks Access 2 July 28th, 2006 06:58 PM
help with DateDiff isaac2004 Classic ASP Basics 9 January 16th, 2006 02:34 AM
Using DateDiff iancrabtree Access 2 November 27th, 2005 07:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.