DateDiff: How soon is now() ?

| No Comments | No TrackBacks

For a grad school project we need to build a system that bills people by the amount of time they rent a car. Thus, I needed to use the DateDiff function of VB and SQL in Access. I looked it up using Access help and got to the right MSDN page:

Syntax

DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]])

They tell you that interval is a String and link to what a string is. The part they don't say explicitly is that you need to enclose the interval value in quotation marks. "Of course," you say, "It's a string." Is it too much to ask for an example showing it in use with the quotation marks? e.g.

In Microsoft Access:
WHERE (((Rentals.CarOut)=True)) AND ((DateDiff("h",Rentals.DropOffDate,Now())>3));
In Microsoft SQL: (Transact-SQL for SQL 2000/2005)
WHERE (((Rentals.CarOut)=True)) AND ((DateDiff("h",Rentals.DropOffDate,GETDATE())>3));

Where h is the code for hours.

I just wanted to write this down someplace before I forget it. And why must Access and T-SQL be different? Now() doesn't work in T-SQL and GETDATE() doesn't work in Access.

No TrackBacks

TrackBack URL: http://cw.sampas.net/cgi-bin/mt5/mt-tb.cgi/113

Leave a comment

About this Entry

This page contains a single entry by Larry published on April 25, 2006 3:48 PM.

The hits I get after updating this blog: was the previous entry in this blog.

Ruby on Rails and Security is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.