© 2024 IQVIA - All Rights Reserved

Date Conversions

Summary

ClinSpark’s Javascript runtime does not support all of the recent Javascript features, and it does not have access to date parsing libraries such as moment.js.

As such, for common tasks such as date comparisons, custom parsing of date inputs is sometimes required.

Here are some examples showing how to parse common date Strings.

Formal Expression

/** * Parses a date with format ddmmmyyyy * like 01Feb2019 */ function parseDate1(input) { return new Date(input.substring(5), threeDigitMonthToDigit(input.substring(2,5)), input.substring(0,2)); } /** * Parses a date with format yyyy-mm-dd * like 1992-06-27 */ function parseDate2(input) { logger('input '+input); var fields = input.split('-'); logger('fields '+fields); return new Date(fields[0], fields[1], fields[2]); } function threeDigitMonthToDigit(monthString) { var map = { jan: 0, feb: 1, mar: 2, apr: 3, may: 4, jun: 5, jul: 6, aug: 7, sep: 8, oct: 9, nov: 10, dec: 11 }; return map[monthString.toLowerCase()]; }

 

Exported and Printed Copies Are Uncontrolled