date -> formatted string in a labkey validation script? | Ben Bimber | 2010-10-15 12:41 | |||||||||||||||
Status: Closed | |||||||||||||||||
in a validation script I am creating a generating the description field (basically a multi-line summary of that record). I want to do something like 'Date: XXXX-XX-XX'. Note this is formatted. the available date function is validation scripts is a little quirky, so below is what I came up with. it seems to work for single record imports (ie. 'insert new'). however through the ETL a lot of dates become 'NA-NA-NA'. Could this be related to what type of date object is being passed? in other situations we had to do the following to parse a date: new java.util.Date(java.util.Date.parse(row.Date)); I'm hoping to figure out the least fragile approach that will work no matter what import path the data uses. thanks for any help or suggestions. here's what i have: dateString: function (date){ //TODO: do better once more date functions added if(date){ date = new Date(date); return (date.getFullYear() ? date.getFullYear()+'-'+(date.getMonth()<10 ? 0:'')+date.getMonth()+'-'+(date.getDate()<10 ? 0:'')+date.getDate() : ''); } else return ''; }, dateTimeString: function (date){ if(date){ date = new Date(date); return date.getFullYear()+'-'+(date.getMonth()<10 ? 0:'')+date.getMonth()+'-'+(date.getDate()<10 ? 0:'')+date.getDate() ' '+date.getHours()+':'+date.getMinutes(); } else return ''; }, |
|||||||||||||||||
| |||||||||||||||||