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

yes

please take a look on below screenshot try to implement same.Screenshot 2023-07-22 at 1.04.10 AM.pngScreenshot 2023-07-22 at 1.04.02 AM.png

Regards,

Ranjit

Hi @Ranjit Nimbalka,  will you apply conditions like
"if I select date 1 so it will show 1st and 22 so there will be 22nd" etc

for example: show 2023-july-1st or 2023-march-22nd etc

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

Samaksh Wani
Giga Sage
Giga Sage

@DEV976 

Try the script which I shared with you it will wo

 

Regards SAMAKSH