Use a function like this - it will honor the time zone.



/** compare selected time with current time
inclTime = true, if you use a DateTimePicker
inclTime = false, if you use a DatePicker
*/
function checkDate( form, fldName, inclTime )
{
// get the selected date as string
var dt_str = form.getAllValues( fldName )[1][0];
// convert to Date object
var dt = form.stringToDate( dt_str, inclTime );
// compare with locate Date/time
var dt_curr = new Date();
if ( dt < dt_curr )
{
form.alert( "The date you have chosen is in the past" );
}
}

In your case call the function like:
checkDate( form, "roleValidTill", true )



On 29.05.2012 08:46, ccikara wrote:
>
> Hi all,
>
> I have a datepicker in a workflow, that will be used to determine when
> a role should expire for a given user...
>
> Now, I need to do some validation on this... I want an error message to
> pop-up if the chosen date is in the past. I have achieved this, but I do
> not think it is 100% correct as the workflow would probably be used in
> different locals, i.e. India and South Africa.
> So I am worried that what I am doing (which currently working in SA)
> wont work in other countries with different local settings:
>
> this is my code:
>
> Corrections / Enhancements comments would be much appreciated!
>
> if (form.getValue("roleValidTill"))
> {
>
> var currentTime = new Date();
> var currentDateString = form.dateToString(currentTime);
> var chosenDateString = form.getValue("roleValidTill").substring(4,6)
> + "/" + form.getValue("roleValidTill").substring(6,8) + "/" +
> form.getValue("roleValidTill").substring(0,4) + " " +
> form.getValue("roleValidTill").substring(8,10) + ":" +
> form.getValue("roleValidTill").substring(10,12) + ":" +
> form.getValue("roleValidTill").substring(12,14);
>
> if (Date.parse(chosenDateString)< currentTime.valueOf())
> {
> form.alert("The date you have chosen is in the past" + "\n" +
> "Please select a date in the future");
> form.setValues("roleValidTill", "")
> }
> else
> {
> }
>
> }
> else
> {
> }
>
>