Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

assign date field to ddmmyy variables

Avatar

Former Community Member

Hi Guys,

I have some code which takes the current date and splits it into dd, mm and yy variables.

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
if(dd<10){dd='0'+dd}
if(mm<10){mm='0'+mm}

this.rawValue = "Text, " + dd+ "-" + mm + "-" + yyyy;

I need to pass this a date from a date field instead of taking to days date but I cannot get it working.

var today = this.parent..DateTimeField2.rawValue;
var dd = today.getDate();
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
if(dd<10){dd='0'+dd}
if(mm<10){mm='0'+mm}

this.rawValue = "TEXT, " + dd+ "-" + mm + "-" + yyyy;

Any help would be appreciated.

Thanks!

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

you can use FormCalc and date patterns to do this easily.

Here an example for the calculate event of DateField2.

It grabs the formatted value of DateField1 (which is DD.MM.YYYY) and formats it to TEXT DD-MM-YYYY.

$ = Num2Date(Date2Num(DateField1.formattedValue, "DD.MM.YYYY"), "'TEXT ' DD-MM-YYYY")

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi,

you can use FormCalc and date patterns to do this easily.

Here an example for the calculate event of DateField2.

It grabs the formatted value of DateField1 (which is DD.MM.YYYY) and formats it to TEXT DD-MM-YYYY.

$ = Num2Date(Date2Num(DateField1.formattedValue, "DD.MM.YYYY"), "'TEXT ' DD-MM-YYYY")