Convert DateTime to XML

kjboloe
Member Posts: 56
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.
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
Kenneth Jarlshøi Bolø
Dynateam A/S
0
Comments
-
Format(currentdatetime,0,9) gives me the following:
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)0 -
Kenneth,
this is caused by your second parameter in the Format function.
You haveformat(DT2TIME(CURRENTDATETIME),0,9)
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,
WillyFostering a homeless, abused child is the hardest yet most rewarding thing I have ever done.0 -
Hi 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.Kind regards
Kenneth Jarlshøi Bolø
Dynateam A/S0 -
Hi Kenneth
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
Thomas0 -
Hi 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.
}
}Kind regards
Kenneth Jarlshøi Bolø
Dynateam A/S0 -
Hi Kenneth
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
Thomas0 -
KYDutchie wrote:Kenneth,
this is caused by your second parameter in the Format function.
You haveformat(DT2TIME(CURRENTDATETIME),0,9)
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
This will work only if you are in the US, in other countries 0 or 1 will use the regional settings of that country.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions