Sir, i want to know the solution for which iam struggling for some days... that is how we have to caluculate difference between two dates such that it have to show the difference in the format yyyy (years):m (months): ww (weaks):w (weakdays) : h (hours): n (minutes) : s (seconds). Sir, to confirm exactly what my doubt mean is...if we go for ebay ..and if we find there the products displaying and the estimated time left to buy... there they show the time left...like that i want if i gve two dates it have to show the exact difference between them......as shown in above format..
thanking you sir.....for providing the oppurtunity and iam waiting for your reply kindly.......
This task is actually much less complicated than it might sound. ColdFusion is quite excellent at both handling and formatting dates. To solve this problem, at least mostly, all we need to is the following:
As you may have read before, ColdFusion's date math makes finding the difference between two dates simple - all we need to do is treat the dates as numbers and do some subtraction:
Launch code in new window » Download code as text file »
When outputting the difference, you have to be careful of the year. That is one tricky thing in ColdFusion. Dates don't start at zero - they start at 12/30/1899. Therefore, when we get our time span, we have to get the difference in years between our time span value and the "start" date of ColdFusion dates. The rest of the formatting should be straightforward.
Running the above code, we get the following output:
0 Years, 8 Months, 12 Days, 9 Hours, 2 Minutes, 42 Seconds
I hope this puts you on the right track.
Download Code Snippet ZIP File
Comments (2) | Post Comment | Ask Ben | Permalink | Other Searches | Print Page
OOPhoto - No More Validation In The Controller
OOPhoto - More Thoughts On Data Validation In Object Oriented ColdFusion Programming
Ben,
I couldn't resist taking this a little further http://www.stephenwithington.com/blog/index.cfm/2008/8/15/Using-ColdFusion-to-Create-an-Ebayesque-Auction-Countdown-Timer-Custom-Tag
Posted by Steve Withington on Aug 15, 2008 at 3:01 PM
@Steve,
That's some slick stuff.
Posted by Ben Nadel on Aug 15, 2008 at 3:06 PM