Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateDiff returning wrong value

Status
Not open for further replies.

huddy33

Technical User
Jan 24, 2011
24
US
I have the following formula for calculating the difference between two dates. I need to run a calculation once I get the correct value.

DateDiff("d",{Meeting.TravelStartDate},{Meeting.TravelEndDate})


The date set for this particular report is 4/29/12 to 5/4/12. It spans two months and a weekend. The formula above is returning 5 when it needs to return 6. I've tried everything, please help!
 

Look at it this way - if your dates were 4/1 and 4/30, that would encompass 30 days. But the difference is 29: 30 - 1.

If you need that extra day just add it in your formula:

DateDiff("d",{Meeting.TravelStartDate},{Meeting.TravelEndDate}) + 1
 
I have tried that but then any date set that doesn't hit that month switch is over by one.
 
any date set that doesn't hit that month switch is over by one
That doesn't make sense. Print out a calendar and try numbering the days, I think you'll find the calculation is correct.

If you want something different when the two dates are in different months, you can make a formula field testing Month(YourDate). Also Year(YourDate) is the two dates might occasionally be in the same date of different years.

[yinyang] Madawc Williams (East Anglia, UK). Using Crystal 2008 with SQL and Windows XP [yinyang]
 

Months, years, and even leap years are all taken into account within the datediff function. You should only have to add one day regardless of the start and stop dates, but please provide two dates where that calculation is incorrect and we can figure out what is happening.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top