|
-
Oct 26th, 2006, 08:29 AM
#1
Thread Starter
Hyperactive Member
DateDiff
I am trying to get total date difference between two dates in crystal formula
for example if i enter
Date1 17/03/2006
Date 2 06/01/2005
The need the result should be like 1 year 2 months ...days etc.,
I used this formula for getting the difference in years
But now i want the full difference in months and days
DateDiff ('yyyy',{Date1},{Date2})
Any ideas please
Thanks
-
Oct 26th, 2006, 11:18 AM
#2
PowerPoster
Re: DateDiff
 Originally Posted by wizkid
I am trying to get total date difference between two dates in crystal formula
for example if i enter
Date1 17/03/2006
Date 2 06/01/2005
The need the result should be like 1 year 2 months ...days etc.,
I used this formula for getting the difference in years
But now i want the full difference in months and days
DateDiff ('yyyy',{Date1},{Date2})
Any ideas please
Thanks
i am not sure on this but i believe days would be:
VB Code:
DateDiff (d,{Date1},{Date2})
and months would be
VB Code:
DateDiff (m,{Date1},{Date2})
-
Oct 26th, 2006, 12:42 PM
#3
Re: DateDiff
Hi
I do not know that what reporting version you are using but
Crystal Reports 8 added some new Date manipulation formulas. The DateDiff function has two forms:
DateDiff (intervalType, startDateTime, endDateTime)
DateDiff (intervalType, startDateTime, endDateTime, firstDayOfWeek)
The first can be used to find the number of intervals between two dates. The IntervalType can be "yyyy" (Years), "q" quarters, "m" (months), "d" (days). See the Crystal Reports help for other variations and some useful examples.
The second form can be used to count a specific day between two dates. It uses the "ww" IntervalType to find the number of the first day of the week.
DateDiff ("ww", {table.datefield1}, {table.datefield2}, crWednesday)
will tell you how many Wednesdays there are between two dates
for more detail click on the crystal report website
http://support.businessobjects.com/
-
Oct 27th, 2006, 02:48 AM
#4
Thread Starter
Hyperactive Member
Re: DateDiff
Thank you very much for your reply.
I am using CR9.
I can get the days and months with different formula
usiing 'yyyy' and 'm' in interval type.
But what i am asking is i want the entire difference in one formula
For example if i give two dates
Date1: 17/03/2006
I need the result should be like 1 year 2 months ...days etc., in one formula
for example if you give
datediff('yyyy',date1,date2) --->the result will be only in years
datediff('m',date1,date2)---> the result will be only in months
etc...
The need the result should be like 1 year 2 months ...days etc., in one formula
Any idea?
Last edited by wizkid; Dec 1st, 2006 at 10:21 AM.
-
Dec 1st, 2006, 10:22 AM
#5
Thread Starter
Hyperactive Member
-
Dec 12th, 2006, 06:38 AM
#6
Addicted Member
Re: DateDiff
Here we go,
cstr(DateDiff ("yyyy", #10/7/1999#, #2/10/2005#))+' year '+cstr(DateDiff ("m", #10/7/1999#, #2/10/2005#))+' month '
Thanks and Regards,
Muhammad Abbas
-
Dec 12th, 2006, 07:10 AM
#7
Thread Starter
Hyperactive Member
Re: DateDiff
My problem is i want the difference between two dates
in days months and year
For example if the two dates are 1/12/2006,3/02/2006
Then the output should be
0 years 2 months 2 days
-
Dec 13th, 2006, 01:31 AM
#8
Re: DateDiff
Here's a function I wrote in VB6 ages ago. By using Crystal's Basic syntax in the formula editor you may be able to duplicate its functionality. Good luck, I'm not assuring that it's bug-free.
VB Code:
Public Function IntervalBTDates(ByVal StartDate As Date, ByVal EndDate As Date) As String
'
' Returns the interval between 2 dates in years, months & days
'
Dim dd As Long
Dim mm As Long
Dim yy As Long
Dim ret As String
Dim tmpDate As Date
'
' Do some basic validation before going any further
'
If StartDate > EndDate Then
MsgBox "Start date must be less than the end date.", vbExclamation, "Date Error"
Exit Function
ElseIf StartDate = EndDate Then
IntervalBTDates = "0 years, 0 months, 0 days"
Exit Function
End If
dd = DateDiff("d", StartDate, EndDate)
mm = DateDiff("m", StartDate, EndDate)
If mm > 0 Then
If Day(StartDate) > Day(EndDate) Then
mm = mm - 1
End If
End If
yy = mm \ 12
mm = mm Mod 12
tmpDate = DateAdd("yyyy", -yy, EndDate)
tmpDate = DateAdd("m", -mm, tmpDate)
dd = Abs(DateDiff("d", StartDate, tmpDate))
If yy = 1 Then
ret = "1 year, "
Else
ret = CStr(yy) & " years, "
End If
If mm = 1 Then
ret = ret & "1 month, "
Else
ret = ret & CStr(mm) & " months, "
End If
If dd = 1 Then
ret = ret & "1 day"
Else
ret = ret & CStr(dd) & " days"
End If
IntervalBTDates = ret
End Function
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Dec 13th, 2006, 04:03 AM
#9
Thread Starter
Hyperactive Member
Re: DateDiff
Thanks pnish
I will try this one in crystal
-
Sep 23rd, 2008, 01:03 AM
#10
New Member
Re: DateDiff
Hi wizkid
i have same problem. what u did for it in crystal report.did u try pnish method in crystal report
Roshani
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|