11.11.2014, 23:11 | #1 |
Участник
|
How to convert a wrong date
Источник: http://alexvoy.blogspot.com/2014/11/...rong-date.html
============== Standard str2date function tries to fix a wrong date. For example, if we got as a parameter fantastic June 31th, it returns us June 30, which can be a bad result for your business case. Happy date converting! There are at least two possible solutions for that. First, by converting the result back to a string and comparing it with the initial string. private container cgiValidateDate(str _dateStr) { date retDate = str2Date(_dateStr, #cgiDateFormat); boolean isOK = true; str madeDateStr = date2StrUsr(retDate, DateFlags::FormatAll); if(retDate == dateNull() || _dateStr != madeDateStr) { error(strFmt("Date %1 is incorrect", _dateStr)); isOK = false; } return [isOK, retDate]; } Second, by using .Net function tryParse. private container cgiValidateDate(str _dateStr) { date retDate; utcDateTime retDateTime; boolean isOK = true; if(!System.DateTime::TryParse(_dateStr, byref retDateTime)) { error(strFmt("Date %1 is incorrect", _dateStr)); isOK = false; } else { retDate = DateTimeUtil::date(retDateTime); } return [isOK, retDate]; } Источник: http://alexvoy.blogspot.com/2014/11/...rong-date.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
|
Опции темы | Поиск в этой теме |
Опции просмотра | |
|