[flexcoders] Re: Time Difference between two columns in DataGrid using itemrenderer
Thanks everyone. Never really could find an easy was to do it in Flex, so I opted for the ease of ColdFusion to get it done quickly on the server side. Two easy CF functions, ParseDateTime and DateDiff. Good news is Flash Builder adds some of the ease of ColdFusion, including CF tags, into Flex! Awesome stuff. Don Kerr --- In flexcoders@yahoogroups.com, Angelo Anolin angelo_ano...@... wrote: I think you would find it better to do the calculation on the database itself. All database have a lot of date/time diff functions which you can use. That way, you all simply bind the data retrieved in your datagrid without the need for calculating it. hth From: Don Kerr fusionp...@... To: flexcoders@yahoogroups.com Sent: Monday, 29 June, 2009 8:51:22 Subject: [flexcoders] Time Difference between two columns in DataGrid using itemrenderer I have two columns in a datadrid, startTime (e.g. 04:30 PM) and endTime (e.g. 06:00 PM). Both are strings and varchar in the database. I want to add a column to the datagrid that displays the difference between these two times expressed in hours (e.g. 1.5 Hours). I'm trying to use an itemrenderer to do this calculation, but I've yet to be successful. Having trouble converting the strings to date, then calculate the hours. Can anyone help? Thanks, Don
[flexcoders] Re: Time Difference between two columns in DataGrid using itemrenderer
Hi Don, The itemRenderer's data Object contains BOTH fields for that row in the dataProvider. You can start by trying to pass the date strings into a DataFormatter and cast as Date, or try DateField.stringToDate(). If the format of the date string isn't compatible, and you can't change what the server sends, you might have to parse the string manually and create a Date object from scratch. Once you have the two date strings converted to Dates, you're ready to compare them. There are a few utilities that you'll be able to find through a search, that work with comparing dates. I found this very quickly (looks like it rounds to full days though): private function calcuateDays( start:Date, end:Date ) :int { var daysInMilliseconds:int = 1000*60*60*24; return ( (end.time - start.time) / daysInMilliseconds ); } You'd probably want to use a Number instead of int, and round the number as desired. And, probably search anyway. -TH --- In flexcoders@yahoogroups.com, Don Kerr fusionp...@... wrote: I have two columns in a datadrid, startTime (e.g. 04:30 PM) and endTime (e.g. 06:00 PM). Both are strings and varchar in the database. I want to add a column to the datagrid that displays the difference between these two times expressed in hours (e.g. 1.5 Hours). I'm trying to use an itemrenderer to do this calculation, but I've yet to be successful. Having trouble converting the strings to date, then calculate the hours. Can anyone help? Thanks, Don