tags:

views:

199

answers:

4

hi guys. I need som help here. need to know how i can compare date from database to today´s date. don´t need it to be very exact. just days will work fine in my case. i need days so i can see if its time for transducer calibration. if date < three month or 90 days then should textbox´s change color to red, showing its time for new calibration. thx by the way. I am using visual studio 2008 C#, and Access 2007

A: 

Maybe the DateTime.FromAODate method is useful for you.

Konamiman
A: 

Have a look at this link

Data type mismatch in criteria expression | Access, OleDb, C#

If i understand correctly from the comment, You can use Date() function to get date today

Something like this

SELECT Table1.Col1, Date() AS Expr1
FROM Table1
WHERE (((Table1.Col1)<Date()));
astander
i am not sure that i can use. through my query i get hold on date from access and this date should be compare to today´s date to see if the differece is greater og samller than 90 !!!
OK, so you want todays date in the query?
astander
A: 

Perhaps:

SELECT Field, Field 
  FROM Table
 WHERE SomeDate < Date() - 90
Remou
It's not clear to me, the human reader, that the INTEGER literal 90 refers to days. I prefer to use the engine's temporal functionality over coercion of DATETIME values to INTEGER. Do you get better performance by not explicitly casting the DATETIME values to INTEGER in your query?
onedaywhen
It is sargable, which will make a huge difference in performance time, and just as easy to guess that 90 means days as that 'd' in a function means days, epecially as 90 days is a very common accounting period.
Remou
"which will make a huge difference in performance time" -- incorrect. Change your word "will" to "could potentially". When a non-sargable query runs in 6 milliseconds no amount of optimization will make a huge difference.
onedaywhen
A: 

Perhaps use the Access Database Engine's temporal functionality e.g. NOW and DATEDIFF():

SELECT column1, column2
  FROM SomeTable
 WHERE DATEDIFF('D', some_date_column, NOW) > 90;

Note due to the nature of Access Database Engine, NOW will return the current timestamp of the client machine rather than that of the machine on which the database file resides i.e. the user can change their local machines' clock to affect the functionality of your SQL code.

onedaywhen
Is this sargable?
Remou
Why are you suggesting the use of Now() when the question explicitly states that the granularity is whole days?
David-W-Fenton
@David W. Fenton: I'd use NOW() for reasons of portability i.e. it maps quite well to Standard SQL's CURRENT_TIMESTAMP. But this has nothing to do with temporal granularity because the Access Database Engine has but one temporal data type being DATETIME which *always* has granularity of one second. It is the D parameter value used in the DATEDIFF function that correctly determines one day granularity.
onedaywhen
@Remou: probably not but premature optimization is not my concern here. I'm more interested in query maintenance i.e. is the construct more intuitive to the human reader? Of course, it's always a balance and things will get load tested at some point but the starting place is good logical code.
onedaywhen
It can make a very big difference indeed, while this reference is not Access, it is, I think, relevant: http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/only-in-a-database-can-you-get-1000-impr
Remou
It can make a *relatively* big difference but if the above query runs in 6 milliseconds (as it does when I tested it on my machine) it can sometimes make negligible absolute difference. Hence the word 'premature' in the term 'premature optimization'.
onedaywhen