Click to See Complete Forum and Search --> : DataDiff & DateAdd
Harrild
Jul 12th, 2000, 03:07 AM
How do you implement the DateDiff and DateAdd commands in Access 97?
Ianpbaker
Jul 12th, 2000, 03:14 AM
Hi Harrild
Do you mean in VBA for access or in SQL
Ian
Harrild
Jul 12th, 2000, 03:31 AM
A SQL would be good plz...
Ianpbaker
Jul 12th, 2000, 03:37 AM
Try this for size
SELECT DATEDIFF(day, date1, column1) AS no_of_days
FROM table1
Harrild
Jul 12th, 2000, 10:12 PM
Ok its a start but i want the date fidd between todays date and the one in the column...
Ianpbaker
Jul 13th, 2000, 03:16 AM
Hi
In that case use
SELECT DATEDIFF(day, getDate(), column1) AS no_of_days
FROM table1
Harrild
Jul 14th, 2000, 06:48 PM
huh?
I still have no idea on how to use it.....what are 'day', 'getdate()' and 'column1'?
Ianpbaker
Jul 17th, 2000, 02:57 AM
Hi harry
Sorry about he delay in reurning bit iv'e been away for the weekend
The datediff function returns the difference in the specified format between two dates. Datediff(datepart,date1,date2). SO in the example I gave you it would return a column called no_of_days consisting of the number of days between today (getdate()) and whatever date that would be in column1.
Ian
Harrild
Jul 20th, 2000, 09:50 PM
And where do i enter that then?
Harrild
Jul 20th, 2000, 10:47 PM
in VBA please
Ianpbaker
Jul 21st, 2000, 02:13 AM
Do You mean you want to check a date in VBA, or you want to return Something in a recordset using the datediff in SQL?
Ian
Harrild
Jul 24th, 2000, 04:07 AM
i got DateAddn in VBA for a form and i want the DateDiff in VBA so i can use it with a form
Ianpbaker
Jul 24th, 2000, 04:19 AM
In VBA,
all you need to do is the following
Dim intDifferenceinDays as integer
intDifferenceinDays = DateDiff("d",now(),somedate)
That will return the difference in days between today(now()) And what ever date you put in the second part.
Hope this helps
Ian
Harrild
Jul 24th, 2000, 04:27 AM
could i out
intDifferenceinDays = DateDiff("d",now(), columname)
cos the diff is from todays date and the other column's date, which in turn gets its value from another column using DateAdd
Ianpbaker
Jul 24th, 2000, 04:31 AM
What do you mean by could i out ?
Harrild
Jul 24th, 2000, 04:46 AM
sorry i meant 'put'
Ianpbaker
Jul 24th, 2000, 05:31 AM
Yes you can
There is no reason wht you can't put a DateAdd inside a DateDiff
Ian
Harrild
Jul 24th, 2000, 05:35 AM
maybe you missunderstood
can i put a column name in place of somedate()?
Ianpbaker
Jul 24th, 2000, 05:40 AM
Yes you can
intDifferenceinDays = DateDiff("d",now(), myrecordset("Mydatecolumn"))
Ian
Harrild
Jul 24th, 2000, 05:54 AM
thanks i let you know how it goes in about 12-24hrs cos the DB is at school at the mo
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.