Hi, I have a problem in a NAV 2009.
I would like to get the correct datetime format for a XML.
I have tried to use :
message(format(DT2DATE(CURRENTDATETIME),0,9) + 'T' + format(DT2TIME(CURRENTDATETIME),0,9));
The result is correct for the date part, but the timepart isn't.
the time is now 12:04.
Microsoft Dynamics NAV Classic
2012-05-02T10:04:28.611Z
OK
I have seen other subjects concerning this issue.
Kind regards
Kenneth Jarlshøi Bolø
Dynateam A/S
0
Comments
It's currently 13:45
Microsoft Dynamics NAV Classic
2012-05-02T11:45:26.507Z
The 2 hours less should be because it's GMT+2 (daylight savings is in effect)
|To-Increase|
this is caused by your second parameter in the Format function.
You have The 9 indicates you switch to XML date.
The Z indicates that the time is expressed in 'Zulu' time which is GMT.
If you use either 0 or 1 instead of the 9 you should be fine.
Hope this helps,
Regards,
Willy
I have tried it, but it doesn't give me the correct datetime format for XML
http://www.w3.org/TR/NOTE-datetime
I have made a solution so that I get a converted string : DD:MM:YYYYTHH:MM:SS
Thanks for all your help.
Kenneth Jarlshøi Bolø
Dynateam A/S
Is it possible to share your solution? And last but not least: What were the requirements and why was the xml format with "zulu" notation not suitable?
Thanks
Thomas
The Zulu time isn't correct in Denmark, because it is 2 hours behind.
Date : 3/5-2012, time : 08:55:31 = 2012-05-03T08.55.31
We have ignored the timezone for the moment, because the company I integrate with is also placed in Denmark \:D/
This is my solution :
OBJECT Codeunit 90000 test
{
OBJECT-PROPERTIES
{
Date=03-05-12;
Time=08:52:56;
Version List=BDL1.24;
}
PROPERTIES
{
OnRun=VAR
DateVar@1000000000 : Integer;
BEGIN
MESSAGE(DateTimeToText(CURRENTDATETIME));
END;
}
CODE
{
VAR
TimeVar@1000000000 : Time;
LOCAL PROCEDURE DateToText@1000000002(VarDate@1000 : Date) : Text[20];
BEGIN
IF VarDate = 0D THEN
EXIT('');
EXIT(FORMAT(VarDate,0,'<Year4>-<Month,2>-<Day,2>'));
END;
PROCEDURE DateTimeToText@1000000010(VarDateTime@1000000000 : DateTime) : Text[30];
BEGIN
VarDateTime := ROUNDDATETIME(VarDateTime);
IF DT2DATE(VarDateTime) = 0D THEN
EXIT('');
EXIT(DateToText(DT2DATE(VarDateTime)) + 'T' + TimeToText(DT2TIME(VarDateTime)));
END;
LOCAL PROCEDURE TimeToText@1000000008(VarTime@1000 : Time) : Text[20];
VAR
Hours@1000000000 : Text[2];
Minuts@1000000001 : Text[2];
Seconds@1000000002 : Text[2];
BEGIN
IF VarTime = 0T THEN
EXIT('00.00.00');
Hours := FORMAT(VarTime,0,'<Hours24,2>');
IF COPYSTR(Hours,1,1) = ' ' THEN
Hours := '0' + COPYSTR(Hours,2,1);
Minuts := FORMAT(VarTime,0,'<Minutes,2>');
Seconds := FORMAT(VarTime,0,'<Seconds,2>');
EXIT(Hours + '.' + Minuts + '.' + Seconds);
END;
BEGIN
END.
}
}
Kenneth Jarlshøi Bolø
Dynateam A/S
Thanks, thats why I asked. Imo you can use Zulu-Time, but in this case you have to consider the offset if you need local time. And the offset is not always the same because of daylight saving period in summer months. Whether to use Zulu-Time or local time of course depends on the use case of the application.
Regards
Thomas
This will work only if you are in the US, in other countries 0 or 1 will use the regional settings of that country.