#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
DateDiff() problem Brad Excel Programming 6 March 30th 09 02:34 PM
datediff help ina Excel Programming 4 April 24th 06 09:44 AM
DateDIFF Paul Breslin Excel Programming 1 December 12th 05 03:09 PM
Help with datediff vba John Excel Programming 4 February 16th 05 01:56 PM
DateDiff in Excel JE McGimpsey Excel Programming 0 May 11th 04 05:07 PM


All times are GMT +1. The time now is 02:05 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"