Copy link to clipboard
Copied
Hi guys, I'm currently using the following script for my day
// get the date from the "Date1"
var d = new Date(this.getField("Date1").value);
if (!isNaN(d.getDay()))
{
switch (d.getDay())
{
case 0:
event.value = "Sun";
break;
case 1:
event.value = "Mon";
break;
case 2:
event.value = "Tue";
break;
case 3:
event.value = "Wed";
break;
case 4:
event.value = "Thu";
break;
case 5:
event.value = "Fri";
break;
case 6:
event.value = "Sat";
break;
default:
event.value = "";
}
}
else
{
event.value = "";
}
My problem here is that for exemple.. today the 28th says TUESDAY not Wednesday... I'm extremely confused. Any ideas?
Assuming the value of your field is a string, you need to parse it into a Date object using something like the code below. Adjust for the format of your date string.
var d= util.scand("mm/dd/yyyy", this.getField("Date1").value);
Copy link to clipboard
Copied
Assuming the value of your field is a string, you need to parse it into a Date object using something like the code below. Adjust for the format of your date string.
var d= util.scand("mm/dd/yyyy", this.getField("Date1").value);
Copy link to clipboard
Copied
Thanks guys finaly got this working!!! Im in no way a java scripter so this helped tremendously.
Again thank you!
Copy link to clipboard
Copied
I would set my entry date field format to one of the standard date formats and use the util.scand method as mentioned to create a date object. You can then simplify your code by using the util.printd method to format the 3 character day of the week from the date object.
Your script with error detection could be:
// get the date from the "Date1"
var oDateField = this.getField("Date1");
if(oDateField == null) {
app.alert("Error accessing Date1 field", 0,1, "Field Error");
} else {
if(oDateField.valueAsString == ""){
event.value = "";
} else {
var oDate = util.scand("dd-mmm-yyyy", oDateField.valueAsString);
if(oDate == null) {
app.alert("Date conversion error " + oDateField.valueAsStirng, 0,1, "Date Conversion Error");
} else {
event.value = util.printd("ddd", oDate);
} // end date object null;
} // end field value not null;
} // end date field not null;
This code catches bad field names and incorrect date strings. You will need to adjust the date format for the util.scand method to match the input field's date format.