dates in text fields

Hi everyone

I am having one of those brain explosion days. i know this can done but…

i have a calculated text field that i want to take the value of either numbers or dates. When it calculates as a date the date doesn’t format as dd-MM-YYYY.

I have tried to use utils.dateFormat and various date functions till my head hurts.

Would appreciate any help.

What is the result of your calculation?
It works fine here when doing:

var resultText = '07/24/2006';
dateField = new Date(resultText);
var formattedDate = utils.dateFormat(dateField, 'dd-MM-yyyy');

Hi Joas

Thanks for your reply,

If i run this as a method

if (life_type == ‘Days’)
{
var c_date = utils.dateFormat(dueat_af_date, ‘dd-MM-yyyy’);
dueat_af_any = c_date;
}

it works and the value is sent to the text field: dueat_af_any.

If i create a calculated text field (dueat_af_any) and use the calculation:

if (life_type == ‘Days’)
{
var c_date = utils.dateFormat(dueat_af_date, ‘dd-MM-yyyy’);
return c_date;
}

the field is blank!

You’re using ‘dueat_af_any’ as both the input and the output for your calculation and that’s why it doesn’t work and why your field stays empty.

You should use another field or a global instead.

Hi Joan

Thanks for your patience.

my 3 fields are:

life type (text)
dueat_af_date (datetime - stored calc)
dueat_af_any (text - calc)

in the calculated text field, dueat_af_any is not used in the definition, ie:

if (life_type == ‘Days’)
{
var c_date = utils.dateFormat(dueat_af_date, ‘dd-MM-yyyy’);
return c_date;
}

again this will work as a method but not as a calc. this can be simplified further as a method:

if (life_type == ‘Days’)
{
dueat_af_any = utils.dateFormat(dueat_af_date, ‘dd-MM-yyyy’);
}

as a calc. field ‘dueat_af_any’ the following calculation definition does not work.

if (life_type == ‘Days’)
{
return utils.dateFormat(dueat_af_date, ‘dd-MM-yyyy’);
}

Again i don’t understand why it works as a method and not a calculation.

Thanks

hmmm, I mixed up both the dueat_af_-fields in your code :?

I tried to reproduce the problem now, but everything was just fine here. Can you perhaps create a small sample solution and post it here?

Hi Joas

Thanks for you reply, i have attached a test file for you to look at.

I have identified the problem but don’t know how to fix it.

if you change the combo box to ‘number’ the yellow field returns the number from the blue number field. if you change the combo box to ‘date’ it should return the date from the blue date field but doesn’t.

the field ‘c_date’ is itself a calculation which adds a number of days to a date which works fine.

the calculation for c_text is:

if (type_test == ‘number’)
{
return number_test;
}
else if (type_test == ‘date’)
{
return utils.dateFormat(c_date, ‘dd-MM-yyyy’);
}

if c_date was a datetime field and not a calculation this works fine as you have already tested, but does not calculate if the c_date is a calculated datetime field.

This is where my problem lies, calculating a date into a text field from an existing calculated date.

Would appreciate any help.

test.servoy (5.74 KB)

Hi Joas

Any ideas on this one?