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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date stored as a number 1

Status
Not open for further replies.

melaniecarr23

Programmer
May 2, 2005
79
US
Someone wrote a program for us using access as the backend database. I have linked to one of their tables so I can run reports off it. The problem is pulling records by date.

7/14/05 is stored as 38547 for example.

How am I supposed to do queries using the date? I can format it as mm/dd/yyyy, but when using now() in the criteria I get no records and I know there are records for today's date.

WHY does this not work?

Thanks,
Melanie
 


Hi,

Microsoft Dates are just numbers! 38547 is july 14, 2005.

When you compare convert Now() to an integral number like this
Code:
....
Where MyDate < CLng(Now())


Skip,
[sub]
[glasses] [red]Be advised:[/red]We know Newton's 3 Laws. But did you hear about the [red]FOURTH???[/red]
Only ONE fig per cookie![tongue][/sub]
 
Now doesn't return an integer, but a double, so if you are comparing a date (long integer) with now (double), you won't get a match, try either Date() or Int(Date)

Roy-Vidar
 
Roy,
But Skip was casting Now() with Clng, so that would work.

I'm not sure about the rounding...if Now() is 11:59 PM if it rounds to the next day, so Fix() I believe takes care of that.
--Jim
 
jsteph,
I think I tried to answer the OP's question about why Now() didn't work in the criteria row of the query, and suggested the Date() function in stead, which doesn't need any conversion to match the numbers...

If you're suggesting that the Int function I mentioned may have some rounding problems, and to use the Fix function in stead, I think you'll need negative values for that to make any difference on the rounding (dates earlier than 30/12/1899) - but, as stated, if using the Date() function as I suggested, there's really no need for any of them, just use Date()...

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top