Is it possible to change dateTime field to 12 hour format without changing global settings?

shanerodgers
Kilo Expert

Hey, I have a field that is auto-filled with the submission date after a forms status changes to submitted. Is it possible to have this field in a 12 hour format as opposed to a 24 hour format without changing the global settings?

Field:

SubmissionDate.PNG

6 REPLIES 6

shanerodgers
Kilo Expert

I attempted to do this in a business rule but it did not work as it wasn't a valid dateTime format.


(function executeRule(current, previous /*null when async*/) {



//current.u_submitdate = gs.nowDateTime();


var currentDate = gs.nowDateTime();



var time = currentDate.slice(-8); //find out the hours and minutes of submission date. This is needed to change 24 hour time to 12 hour.


var hoursSubmitted = time.slice(0,2);


var minutesSubmitted = time.slice(3,5);


var amORpm = "am";



var myUserObject = gs.getUser(); //get users timezone.


var userTimezone = myUserObject.getTZ();



if(hoursSubmitted >= 12){


amORpm = "pm";


if(hoursSubmitted > 12){


hoursSubmitted = hoursSubmitted - 12;


}


}



var newTime12Hour = hoursSubmitted + ":" + minutesSubmitted + " " + amORpm;


var dateTime12Hour = currentDate.replace(time, newTime12Hour);



current.u_submitdate = dateTime12Hour;



gs.addInfoMessage(userTimezone + ' ' + time + ' HH:' + hoursSubmitted + ' MM:' + minutesSubmitted + ' newTime' + newTime12Hour + ' dateTime ' + dateTime12Hour);


})(current, previous);


Gaurav Bajaj
Kilo Sage

Hi Shane,



If you are looking for only one field here, then you can try the display part with onload client script where you can change the format with basic javascript methods.




find_real_file.png



Thanks


Gaurav


Thanks for your help. It doesn't seem to let you change the dateTime field even in an onLoad client script using g_form.setValue if it's not the correct format? Or should I use something else and not g_form.setValue?


Hi Shane,



I am afraid that even if we format the date as per our need but then its not gonna save it back in the system showing it as "invalid date".


All you can do is to set the display it in 12 hours format.


and yes you will have to take care of right format too.



That's all I could come up with at this point of time


find_real_file.png