Hi.
- According to the manual, you can set a date using
Date.Set()
with a string likeyyyy-mm-dd hh:mm:ss.mmm
. But it seemsSet()
doesn't like milliseconds.
e.g.
var regex = /^(?:(0?[1-9]|[12][0-9]|3[01])[-/](0?[1-9]|1[0-2])[-/]((?:1[6-9]|2[0-9])\d{2})(?:\s(0?\d|1\d|2[0-3]):([0-5]?\d)(?::([0-5]?\d)(?:\.(\d{1,3}))?)?)?|((?:1[6-9]|2[0-9])\d{2})[-/](0?[1-9]|1[0-2])[-/](0?[1-9]|[12][0-9]|3[01])(?:\s(0?\d|1\d|2[0-3]):([0-5]?\d)(?::([0-5]?\d)(?:\.(\d{1,3}))?)?)?)$/;
var str = '1991-12-31 02:59:01.100';
DOpus.Output('Valid:'+regex.test(str));
var date = DOpus.Create().Date();
date.Set(str); //error when ms are present
DOpus.Output(date.Format('','nSM'));
Without milliseconds it works fine.
- Although you can use regex to validate the format of a datetime, there are certain things you can't do, like validate the value itself. Since it seems
Date.Set()
throws an error when you pass an incorrect one (correct me if I'm wrong, please), could it be changed to returntrue/false
instead as a validation method?
Thanks.