- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 04:43 AM
Hi All,
I want to apply date Formatting such that if it 1 then it should be "1st", 2 for "2nd ", 3 for "3rd" and remaining all for "4th or 5th"
i am using this code,
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]+"th-"+name+"-"+newValue[2];
g_form.setValue('u_date2',date2);
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 07:19 AM - edited 07-25-2023 07:20 AM
Hello @DevYadav
I got you, your date format is some what different, no worries :-
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 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);
}
This will Definitely Works, Plz try it.
Plz Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 08:24 AM
Hello @DevYadav
Use this script for your requirement :-
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 dateM = newValue[2].split("");
var date2;
if((dateM[0]==0 || dateM[0]==2||dateM[0]==3) && (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);
}
Plz Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 07:58 AM
Hi @Samaksh Wani, all your code is correct except it is showing th with 31.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 08:24 AM
Hello @DevYadav
Use this script for your requirement :-
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 dateM = newValue[2].split("");
var date2;
if((dateM[0]==0 || dateM[0]==2||dateM[0]==3) && (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);
}
Plz Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 08:59 AM
Hello @DevYadav
Plz mark my latest script response as Accept. it will help future readers for getting correct solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 06:26 AM
Hello @DevYadav
Just now i saw your requirement clearly sorry i gave wrong code previously, Just try it, will work.
Plz Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.
Regards,
Samaksh