AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 09.10.2012, 17:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,643 / 848 (80) +++++++
Регистрация: 28.10.2006
ax-erp: Dynamics Ax 2009 using the DateTimeUtil
Источник: http://microsoft-dynamics-ax-erp.blo...etimeutil.html
==============


Since i’m getting a lot of google hits on my Dynamics Ax – workdays to days post, i’ve decided to blog some more about it. The DateTimeUtil class is actually a wrapper of the .NET DateTime class.
A first thing to remember when using UtcDateTime EDT’s is that it is stored like the name says as Coordinated Universal Time.
The controls on the form will translate the DateTime to the timezone of the client. Now keeping this in mind is very important when mixing date, time and datetime controls. The following example will make it more clear.
The first field is a UtcDateTimeEdit control with a data method that returns DateTimeUtil::UtcNow().

As you can see the time is 08:58, but the first control on the form shows 10:58. This is correct because my client timezone is (GMT+01:00) Brussel, Kopenhagen, Madrid, Parijs and it’s summer time.
The second field is a TimeEdit control with a data method that returns DateTimeUtil::time(DateTimeUtil::utcNow()), this isn’t correct because it will always return the time in the UTC timezone and the control will not translate it to the correct timezone.
The third field is another TimeEdit control with a data method that returns TimeNow(), this is correct because the TimeNow method will also apply the client/server (depending on the tier) timezone.
this also applies to field in a table.

Another way to use Time controls and the DateTimeUtil is using the applyTimeZoneOffset method.
UtcDateTime ret;
;

ret = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::utcNow(),TimeZone::GMTPLUS0100BRUSSELS_COPENHAGEN_MADRID);

return DateTimeUtil::time(ret);

but this is a lot of code for a rather more simple thing
A second thing to remember, when querying with a date on UtcDateTime fields make sure you select the whole day from 00:00:00 to 23:59:59.
For this I like to implement a method on the Global class, it’s keeps you’re queries cleaner It works the same way as all .NET developers use, Add a with time 0 and subtract a second.
static UtcDateTime dateCompare(date _date,
boolean _toDate = false)
{
UtcDateTime ret;
;

if(_toDate)
{
ret = DateTimeUtil::addSeconds(DateTimeUtil::newDateTime(_date + 1,0),-1);
}
else
{
ret = DateTimeUtil::newDateTime(_date,0);
}

return ret;
}

So you’re query looks like this.
<div class="wp_syntax" style="background-color: #f9f9f9; border: 1px solid silver; color: #110000; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 24px; margin: 0px 0px 1.5em; outline: 0px; overflow-x: auto; overflow-y: hidden; padding: 0px; vertical-align: baseline; width: 584px;">Date currectDate = SystemDateGet();
SalesLine salesLine;
;

while select salesLine
where salesLine.createdDateTime >= dateCompare(currectDate)
&& salesLine.createdDateTime <span style="border: 0px; color: #00007f; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
crminthefield: Podcast and Overview: Microsoft Dynamics CRM 2011 Update Rollup 10 Blog bot Dynamics CRM: Blogs 0 17.08.2012 03:27
dynamics-ax: Microsoft Highlights New ERP Public Sector Capabilities for AX 2012 Blog bot DAX Blogs 0 23.05.2011 19:11
Dynamics AX Sustained Engineering: Microsoft Dynamics AX 4.0 and AX 2009 are compatible with Microsoft Windows 7 and Microsoft Windows Server 2008 R2 Blog bot DAX Blogs 0 22.09.2009 04:06
Dynamics AX: Managing Your Supply Chain Using Microsoft Dynamics AX 2009 - Book Review Blog bot DAX Blogs 0 31.03.2009 23:06
axStart: Microsoft Dynamics AX 2009 Hot Topics Web Seminar Series Blog bot DAX Blogs 0 06.08.2008 12:05

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 06:01.