Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculations with date

Status
Not open for further replies.

mortkc

MIS
Apr 23, 2001
84
US
I have a short program that is pulling a date from a database field. I want to take the difference between that date and the current date to see if the date has already passed, and I am using the following code:

Do While Not objRS.EOF

strDateCalc = DateDiff("d",date,objRS("EndDate"))

If strDateCalc < 0 Then strSQL = &quot;UPDATE Auctions SET BidStatus = No;&quot;
'strSQL = &quot;UPDATE Auctions SET BidStatus = NO;&quot;

Response.Write strDateCalc & &quot;<BR>&quot;
Response.End

Set objCmd = Server.CreateObject(&quot;ADODB.Command&quot;)

' ---------------------------------Set the command object properties-------------------------------

Set objCmd.ActiveConnection = objConn
objCmd.CommandText = strSQL
objCmd.CommandType = adCmdText

' ------------------------------------Execute the command-----------------------------
objCmd.Execute
Set objCmd = Nothing

objRS.MoveNext

Loop


The code is looping, but it is giving back the wrong numbers. If I do a response.Write strDateCalc, followed by a response.End, it is not calculating properly. Can anyone tell me what I cam doing wrong. Thanks
 
If you are trying to get dates that have already passed...

strSQL = &quot;select * from myTable where dateField < '&quot; & date & &quot;'&quot;

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
this is a lot easier, but it now gives me:

Error Type:
Microsoft JET Database Engine (0x80040E07)
Data type mismatch in criteria expression

The field I am pulling from is a date field in an Access Database. The line reads:

strSQL = &quot;SELECT Auctions.AuctionID,Auctions.EndDate, Auctions.Bidder, Auctions.StartBid, Auctions.CurrentBid, Auctions.BidStatus, Items.ItemID, Items.ItemDetails, Items.ItemName, Items.SerialNumber, Items.CategoryID FROM QryItemAuction WHERE EndDate <'&quot;& date &&quot;'&quot;
 
I think that if you're using Access you need pound signs around the date value...

&quot;select * from myTable where dateField < #&quot; & date & &quot;#&quot;
 
Look in the FAQs for this forum.

Start with this one: faq333-3048
look at Reference 8,10

-pete
I just can't seem to get back my IntelliSense
 
If your using Access, your date's should be enclosed in #'s

strSQL = &quot;SELECT Auctions.AuctionID,Auctions.EndDate, Auctions.Bidder, Auctions.StartBid, Auctions.CurrentBid, Auctions.BidStatus, Items.ItemID, Items.ItemDetails, Items.ItemName, Items.SerialNumber, Items.CategoryID FROM QryItemAuction WHERE EndDate <#&quot;& date &&quot;#&quot;

BDC.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top