Home > Flex, code > isDate function for Flex…found!

isDate function for Flex…found!

Well, sort of…

ColdFusion has a very nice “isDate()” function that allows you to pass in a variety of formats, and check whether the passed in value is a date. I had been searching for something similar in Flex, but had very little success until I started playing around with different functions myself.

I had been writing a custom controller for a datagrid which allowed passing in data from an object or table and displaying it in an editable datagrid. The problem I ran into was that depending on the data returned, trying to set those values back to the object that I was using, caused me some issues (such as trying to set a date stored in a text field, back to the object as a “new Date” value). After trying many different kinds of things, I found that the parse function of date works very nicely.

You can do something like

    if ( Date.parse( myDateField.text ) ) {
        myObj.recordingDate = Date.parse( myDateField.text );
    }

If you pass it a value that is not a valid date, the statement returns false.

Anyway, I had been searching around for a while trying to find something that would allow me to check for isDate and this fit the bill nicely. It also allows you to pass in quite a varied type of date formatting and it still recognizes it. Very powerful feature, it seems.

Categories: Flex, code Tags: , ,
  1. Tony Monast
    July 26th, 2010 at 14:48 | #1

    Hi,

    Two years later, it’s still working! Thanks for the tip!

  1. No trackbacks yet.