How do you implement the DateDiff and DateAdd commands in Access 97?
Printable View
How do you implement the DateDiff and DateAdd commands in Access 97?
Hi Harrild
Do you mean in VBA for access or in SQL
Ian
A SQL would be good plz...
Try this for size
SELECT DATEDIFF(day, date1, column1) AS no_of_days
FROM table1
Ok its a start but i want the date fidd between todays date and the one in the column...
Hi
In that case use
SELECT DATEDIFF(day, getDate(), column1) AS no_of_days
FROM table1
huh?
I still have no idea on how to use it.....what are 'day', 'getdate()' and 'column1'?
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
And where do i enter that then?
in VBA please
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
i got DateAddn in VBA for a form and i want the DateDiff in VBA so i can use it with a form
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
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
What do you mean by could i out ?
sorry i meant 'put'
Yes you can
There is no reason wht you can't put a DateAdd inside a DateDiff
Ian
maybe you missunderstood
can i put a column name in place of somedate()?
Yes you can
IanCode:intDifferenceinDays = DateDiff("d",now(), myrecordset("Mydatecolumn"))
thanks i let you know how it goes in about 12-24hrs cos the DB is at school at the mo