Working with DateTime in C/AL

EBotha
Member Posts: 6
Hi,
I need to subtract 2 hours from the current date and time, and then convert to ISO8601. I am able to get the new DateTime, but cannot find anything on the conversion? Would there be a simpler way to do this?
NewDate := CreateDateTime(TODAY,TIME);
NewDate - (2 * 60 * 60 * 1000)
T.I.A.
I need to subtract 2 hours from the current date and time, and then convert to ISO8601. I am able to get the new DateTime, but cannot find anything on the conversion? Would there be a simpler way to do this?
NewDate := CreateDateTime(TODAY,TIME);
NewDate - (2 * 60 * 60 * 1000)
T.I.A.
0
Answers
-
NewDate := CURRENTDATETIME - (2 * 60 * 60 * 1000)Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-031 -
Thank you. I am getting the correct date and time, but any idea also to get it in ISO8601 format, eg.g. "2018-07-02T09%3A25%3A05Z"?0
-
NewDateTxt := FORMAT(NewDate, 0, 9) - close enough?Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-031 -
@Slawek_Guzek I tweaked it a little to remove the milliseconds from the string, but it worked. Looks like the below:
NewDateTxt := FORMAT(CURRENTDATETIME, 0, 9);
NewDateTxt := DELSTR(NewDateTxt,STRPOS(NewDateTxt,'.'), 4);
NewDateTxt := replaceString(FORMAT(NewDateTxt), ':', '%3A');
Result = 2018-07-02T12%3A40%3A05Z
Not sure if this is the best way but works for me. Thank you very much for your help0 -
I'd suggest you to read about formating the FORMAT output, and use custom formatting string - rather than manipulating the text output of FORMAT function to get rid of miliseconds. Your current code is going to produce incorrect results if the milisecond part will be shorten than 4 characters.
Alternatively you can use the ROUNDDATETIME function to round the CURRENTDATETIME output to full sencodsSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-031 -
@Slawek_Guzek I took your advice and modified the code:
Date1 := CREATEDATETIME(TODAY,TIME - (3600000*2));
TimeStamp := FORMAT(Date1,0,'<Year4>-<Month,2>-<Day,2>T<Hours24>%3A<Minutes,2>%3A<Seconds,2>Z');
Result : 2018-07-05T10%3A32%3A32%3A45Z
Thank you for helping a newbie out. Much appreciated.0 -
everyone here was a newbie onceSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-031
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