views:

225

answers:

2

How to create a DateField in flex, that would disable all the dates before today's current date.

<mx:DateField id="dateField2" yearNavigationEnabled="true" 
                disabledRanges="{[ {rangeEnd: new Date(dateBeforeCurrentDate} ]}" color="0x000000"/>

I understand I will have to do sometime like the code above. But I don't know how to get dateBeforeCurrentDate, so that all the date from yesterday will be disabled.

Please let me know.

Regards Zee

+1  A: 

Hi,

I guess you need this:

<mx:DateField disabledRanges="{[{rangeEnd: new Date()}]}"/>

Current date is just "new Date()".

Sergey Z.
no .. actually I am looking for a day before currentDate. I am sorry for not being clear in my question.
Zeeshan Rang
+2  A: 

I think you're stuck with millisecond arithmetic. That's what's used in Adobe's docs:

function getYesterday():Date {
    var today:Date = new Date();
    var millisecondsPerDay:Number = 1000 * 60 * 60 * 24;

    var yesterday:Date = new Date();
    yesterday.setTime(today.getTime() - millisecondsPerDay);
}

You could probably pull in a library to do this (see, e.g. Flex Date Utils) if you're going to be doing any more date arithmetic.

Michael Brewer-Davis