Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default datediff in excel 2003.. Agecalculation

Strange... I simply can't get datediff to work in a string in Excel. Is it
only suppose to work in VBA ?
What I am trying to do is :

=DATEDIF(A1,NOW(),"y") & " years, " & DATEDIF(A1,NOW(),"ym") & " months, " &
DATEDIF(A1,NOW(),"md") & " days"

I have to calculate the age in F17:F500 from cell E17:E500

Can anyone help ?
Shamran


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 618
Default datediff in excel 2003.. Agecalculation

Hi

from Chip Pearson's page on DATEDIF
http://www.cpearson.com/excel/datedif.htm
You can't use DATEDIF in VBA code. VBA provides a function called DateDiff
(note, two f's), but DateDiff doesn't supoort the "ym", "md", and "yd"
interval arguments that DATEDIF does. To compute age in VBA, you have to
do the math on your own.
Function Age(Date1 As Date, Date2 As Date) As String
Dim Y As Integer
Dim M As Integer
Dim D As Integer
Dim Temp1 As Date
Temp1 = DateSerial(Year(Date2), Month(Date1), Day(Date1))
Y = Year(Date2) - Year(Date1) + (Temp1 Date2)
M = Month(Date2) - Month(Date1) - (12 * (Temp1 Date2))
D = Day(Date2) - Day(Date1)
If D < 0 Then
M = M - 1
D = Day(DateSerial(Year(date2), Month(date2), 0)) + D
End If
Age = Y & " years " & M & " months " & D & " days"
End Function
----

Cheers

JulieD



"-[::::Shamran::::]-" wrote in message
...
Strange... I simply can't get datediff to work in a string in Excel. Is it
only suppose to work in VBA ?
What I am trying to do is :

=DATEDIF(A1,NOW(),"y") & " years, " & DATEDIF(A1,NOW(),"ym") & " months, "
& DATEDIF(A1,NOW(),"md") & " days"

I have to calculate the age in F17:F500 from cell E17:E500

Can anyone help ?
Shamran



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default datediff in excel 2003.. Agecalculation


from Chip Pearson's page on DATEDIF
http://www.cpearson.com/excel/datedif.htm
You can't use DATEDIF in VBA code. VBA provides a function called
DateDiff (note, two f's), but DateDiff doesn't supoort the "ym", "md", and
"yd" interval arguments that DATEDIF does. To compute age in VBA, you
have to do the math on your own.
Function Age(Date1 As Date, Date2 As Date) As String
Dim Y As Integer
Dim M As Integer
Dim D As Integer
Dim Temp1 As Date
Temp1 = DateSerial(Year(Date2), Month(Date1), Day(Date1))
Y = Year(Date2) - Year(Date1) + (Temp1 Date2)
M = Month(Date2) - Month(Date1) - (12 * (Temp1 Date2))
D = Day(Date2) - Day(Date1)
If D < 0 Then
M = M - 1
D = Day(DateSerial(Year(date2), Month(date2), 0)) + D
End If
Age = Y & " years " & M & " months " & D & " days"
End Function
----


Yes that it try ! BUT I simply can't get Dateif to work in a Ceææ either ! I
really don't won't to make any VBA code. I would rather have a simple cell
calculation

Shamran


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default datediff in excel 2003.. Agecalculation


from Chip Pearson's page on DATEDIF
http://www.cpearson.com/excel/datedif.htm
You can't use DATEDIF in VBA code. VBA provides a function called
DateDiff (note, two f's), but DateDiff doesn't supoort the "ym", "md", and
"yd" interval arguments that DATEDIF does. To compute age in VBA, you
have to do the math on your own.
Function Age(Date1 As Date, Date2 As Date) As String
Dim Y As Integer
Dim M As Integer
Dim D As Integer
Dim Temp1 As Date
Temp1 = DateSerial(Year(Date2), Month(Date1), Day(Date1))
Y = Year(Date2) - Year(Date1) + (Temp1 Date2)
M = Month(Date2) - Month(Date1) - (12 * (Temp1 Date2))
D = Day(Date2) - Day(Date1)
If D < 0 Then
M = M - 1
D = Day(DateSerial(Year(date2), Month(date2), 0)) + D
End If
Age = Y & " years " & M & " months " & D & " days"
End Function
----

Cheers

JulieD


Sorry Julie !! The problem was that I am suppose to use DATO.FORSKEL. I HATE
this danish crap ! When I upgrade next time it will deff. be US version !

Regards Jesper !


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 618
Default datediff in excel 2003.. Agecalculation

Hi Jesper

so it's working now? ... great :)
i have enough trouble using the english version of excel i couldn't imagine
having to translate / deal with different function names - eeek!

Cheers
JulieD


JulieD


Sorry Julie !! The problem was that I am suppose to use DATO.FORSKEL. I
HATE this danish crap ! When I upgrade next time it will deff. be US
version !

Regards Jesper !





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default datediff in excel 2003.. Agecalculation


"JulieD" wrote in message
...
Hi Jesper

so it's working now? ... great :)
i have enough trouble using the english version of excel i couldn't
imagine having to translate / deal with different function names - eeek!


Belive me it's hell !


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" LOCATION IN EXCEL 2007 dickvw Excel Worksheet Functions 1 December 14th 07 06:48 PM
Where is DateDiff function in Excel 2002 ? Nigel Welch Excel Worksheet Functions 4 March 4th 05 03:18 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
DateDiff problem Antje Crawford Excel Programming 3 July 8th 03 09:44 PM


All times are GMT +1. The time now is 04:17 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"