separate dates using split function

DEV976
Tera Expert

Hi All, 
i am new to split function. 
I want to separate date, month and year from dd-mm-yyyy format on catalog item and show just month at there.

there are 2 variables. one is date [dt] and second is show date[u_sd]. the requirement is: autopopulate date on show date variable and the date that is present on show date, it's month must be convert into name, like jan for 1 or march for 3 etc.

thanks

2 ACCEPTED SOLUTIONS

Ranjit Nimbalka
Mega Sage

hello @DEV976 ,

write a onchange client script on first date field and try code like below.

 

you can do something like below:-

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var months=["jan","feb","march","april","may","june","july","sep","october","november","december"];
newValue= newValue.split("-",[3]);
var month=newValue[1];
var name=(months[month-1]);
var date2= newValue[0]+"-"+name+"-"+newValue[2];
g_form.setValue('u_date2',date2);
//Type appropriate comment here, and begin script below
 
}
 
 
Screenshot 2023-07-21 at 11.48.54 PM.png
 
Regards,
Ranjit

 

View solution in original post

Hello @DEV976 

 

 

 

 

unction onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

var months=["jan","feb","march","april","may","june","july","sep","october","november","december"];
newValue= newValue.split("-",[3]);
var month=newValue[1];
var name=(months[month-1]);
var dateM = newValue[2].split("");
var date2;
if((dateM[0]==0 || dateM[0]==2) && (dateM[1]==1)) {
   date2= newValue[0]+"-"+name+"-"+newValue[2]+"st";
}
else if((dateM[0]==0 || dateM[0]==2)&& (dateM[1]==2) ){
   date2= newValue[0]+"-"+name+"-"+newValue[2]+"nd";
}
else if((dateM[0]==0 || dateM[0]==2) && (dateM[1]==3) ){
   date2= newValue[0]+"-"+name+"-"+newValue[2]+"rd";
}
else{
 date2= newValue[0]+"-"+name+"-"+newValue[2]+"th";
}
g_form.setValue('u_date2',date2);
}

 

 

 

 

I have tried on my pdi, it is working fine.

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.

 

Regards,

Samaksh

View solution in original post

18 REPLIES 18

Ranjit Nimbalka
Mega Sage

hello @DEV976 ,

write a onchange client script on first date field and try code like below.

 

you can do something like below:-

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var months=["jan","feb","march","april","may","june","july","sep","october","november","december"];
newValue= newValue.split("-",[3]);
var month=newValue[1];
var name=(months[month-1]);
var date2= newValue[0]+"-"+name+"-"+newValue[2];
g_form.setValue('u_date2',date2);
//Type appropriate comment here, and begin script below
 
}
 
 
Screenshot 2023-07-21 at 11.48.54 PM.png
 
Regards,
Ranjit

 

@Ranjit Nimbalka, i've try your code but it is not working

 

@DEV976

please use field names as your field or share the screenshot what error u r getting.

it is catalog variable name:
u_date (from there I am taking date) and write(it contain the july value)

 

so you have two field one is date type second is string and if you select 2023-07-17 in date field then you want to set JULY into second string type field is it right?