AXForum  
Zurück   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Kennwort vergessen?
Registrieren Forum Rules Hilfe Benutzerliste Heutige Beiträge Suchen

 
 
Themen-Optionen Thema durchsuchen Ansicht
Alt 11.11.2014, 23:11   #1  
Blog bot ist offline
Blog bot
Участник
 
25.644 / 848 (80) +++++++
Registriert seit: 28.10.2006
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.



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];
}


Happy date converting!

Источник: http://alexvoy.blogspot.com/2014/11/...rong-date.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
atinkerersnotebook: Walkthrough & Tutorial Summary Blog bot DAX Blogs 1 09.09.2013 09:11
Kurt Hatlevik: How to use dynamic date ranges in RoleCenter Cue’s Blog bot DAX Blogs 0 18.12.2012 09:11
ax-erp: How to extract Date value from a DateTime field Blog bot DAX Blogs 0 11.09.2012 18:11
How to Bulk Convert Leads in Dynamics CRM 4.0 On-Premise Blog bot Dynamics CRM: Blogs 0 12.03.2011 02:16
axStart: How to convert a column in a table to a different type with the same name without losing data. Blog bot DAX Blogs 0 01.02.2008 21:21

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Gehe zu

Рейтинг@Mail.ru
Alle Zeitangaben in WEZ +3. Es ist jetzt 21:55 Uhr.
Powered by vBulletin® Version 3.8.5 (Deutsch)
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.