datediff

M

Mijosuva

Dear Expert

I try to use DateDiff but it doesn't work, when I try to use this simple
function excel say #NAME?

This is what I have

Function session_num(start_date As Date, today_date As Date) As Long


'Determine the # of weeks between today date and Start Date

session_num = DateDiff("ww", today_date, start_date)


End Function
 
J

Jacob Skaria

DATEDIF() is a worksheet function whereas;

DATEDIFF() function is a VBScript function which should work. The syntax is
DateDiff(interval, date1, date2 [,firstdayofweek[, firstweekofyear]]). Try
the below in your immediate window which should return 2 weeks.

DateDiff("w", Date()-14, Date())

If this post helps click Yes
 
R

Rick Rothstein

The VB DateDiff function requires the earlier date to be placed first and
the later date second... you have them reversed. Try this line in your
function instead...

session_num = DateDiff("ww", start_date, today_date)
 
M

Mijosuva

Thanks for the help, but I found the solution, Rick your right but security
option of Macros should be enable.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top