ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   datediff (https://www.excelbanter.com/excel-programming/427703-datediff.html)

Mijosuva

datediff
 
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



Gary''s Student

datediff
 
try:
DATEDIF
in place of:
DATEDIFF
--
Gary''s Student - gsnu200850


"Mijosuva" wrote:

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



Jacob Skaria

datediff
 
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
---------------
Jacob Skaria


"Mijosuva" wrote:

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



Rick Rothstein

datediff
 
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)

--
Rick (MVP - Excel)


"Mijosuva" wrote in message
...
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




Dave Peterson

datediff
 
Chip Pearson has some very nice notes:
http://www.cpearson.com/excel/datedif.aspx

Mijosuva wrote:

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


--

Dave Peterson

Mijosuva

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


"Mijosuva" wrote:

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




All times are GMT +1. The time now is 02:09 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com