So I’ve got this project where a Flex User Interface saves Time information back to a MS SQL database. The thing is, the client wants the time to be stored in a Date typed’ field in the DB. Likewise, I need it to be a date in Flex so that I can do date math sort of functions on it, etc.
The thing is, when I examined my flash remoting calls with Service Capture, I would notice that despite my cfproperty tags and property types in my object in flex, that the times were coming across the wire as Strings! They were in mm:ss format, but because they were being serialized as strings, the Flex UI was casting them as strings. Arrrgggh!
So all these times were now showing up as 00:00 despite coming across correctly (ie 04:19). Well,you know,ColdFusion has a function for everything, so here’s what I did:
Wherever I needed to “fill” my objects, I just used this little bit of code:
– Note, my times were in minutes/seconds format –
object.date = CreateDate(1900,12,31, ListFirst(dbcolumn,':'), ListLast(dbcolumn,':');
So what did this do?
created a new date object. I don’t care about the year, month, and day, so I just used 1900/12/31 as a place holder.
Secondly, by using
I was able to treat the time (mm:ss) format as a list, and use the first/last to get each side of the “:” by treating the “:” as a delimiter. Admittedly, this would not work out so well if you had hh:mm:ss format. However, if all you needed was hours/minutes, this trick would work too.
This totally corrected the problem. Once again, the times are being serialized as dates and all is well in the Flex UI!