What is the best/shortest method of converting XML datetime into NAV datetime?

Slawek_GuzekSlawek_Guzek Member Posts: 1,690
edited 2017-11-27 in NAV Three Tier
yyyy-MM-ddThh:mm into NAV datetime please?
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03

Best Answers

Answers

  • AKAK Member Posts: 226
    I'm sure it isn't the shortest or prettiest method, but it works:
    GetDateFromText(DateTimeText : Text[30]) DateValue : Date
    DateTimeText := COPYSTR(DateTimeText,1,STRPOS(DateTimeText,'T') - 1);
    
    YearText := COPYSTR(DateTimeText,1,STRPOS(DateTimeText,'-') - 1);
    DateTimeText := DELSTR(DateTimeText,1,STRLEN(YearText) + 1);
    
    MonthText := COPYSTR(DateTimeText,1,STRPOS(DateTimeText,'-') - 1);
    DateTimeText := DELSTR(DateTimeText,1,STRLEN(MonthText) + 1);
    
    DayText := DateTimeText;
    
    EVALUATE(DateValue,DayText + '.' + MonthText + '.' + YearText);
    
    GetTimeFromText(DateTimeText : Text[30]) TimeValue : Time
    EVALUATE(TimeValue,COPYSTR(DateTimeText,STRPOS(DateTimeText,'T') + 1,8));
    
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    edited 2017-11-27
    @AK hmm expected / hoped for a one-liner to be frank... :) and not in form of combinig all COPYSTR/STRPOS/DELCHR into one call :)
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • nick_robbonick_robbo Member Posts: 49
    Does Evaluate work?

    TextDateTime := FORMAT(OriginalTextDateTime)
    EVALUATE(DateTime, TextDateTime)
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    @nick_robbo
    Nope. NB: the format you have used is not XML. Try this:
    TextDateTime := FORMAT(OriginalTextDateTime, 0, 9)
    EVALUATE(DateTime, TextDateTime)
    
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Answer ✓
    NavDateTime := DotNetDateTime.Parse(DateTimeText);
    
    That's what I've been looking for :)
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • KishormKishorm Member Posts: 921
    Answer ✓
    The best/shortest method is as follows (doesn’t even require a DotNet variable)...
    EVALUATE(NavDateTime,DateTimeText,9);
    
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Kishorm wrote: »
    The best/shortest method is as follows (doesn’t even require a DotNet variable)...
    EVALUATE(NavDateTime,DateTimeText,9);
    
    Ahh.. Too simple to give it a go :)

    Thanks @Kishorm . THAT was exactly what I was after :)
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Sign In or Register to comment.