Options

Convert text into date

kenlkenl Member Posts: 182
Hello,

I am new to Navision. How to convert a text into date, in format YYYYMMDD ?

eg. "20050121" convert into 2005/01//21

Thanks,

Ken

Comments

  • Options
    kinekine Member Posts: 12,562
    see function EVALUATE...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    kenlkenl Member Posts: 182
    Hello,

    Evaluate give me error.

    Date: MyDate

    Evaluate(myDate, '20050401');

    This gives me a run time error. Seem like evaluate only work when the date format is the same as the window regional setting. :cry:

    Any idea?

    Ken
  • Options
    kinekine Member Posts: 12,562
    Of course the format must be same as set in regional settings else the application do not know what is year, month and day... you must convert the string before converting into date... (switch to format ddmmyyyy for example)
      DateText := COPYSTR(DateText,7,2)+COPYSTR(DateText,5,2) + COPYSTR(DateText,1,4);
    

    This code convert yyyymmdd to ddmmyyyy for example...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    krikikriki Member, Moderator Posts: 9,090
    try this:
    datMyDate := 
      DMY2DATE(
        COPYSTR(txtMyDate,7,2),
        COPYSTR(txtMyDate,5,2),
        COPYSTR(txtMyDate,1,4));
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    kenlkenl Member Posts: 182
    Hello,

    Yeah, we can write our own function for that, just like what you suggest.

    I thought it is a very common task in programming, and I thought it should be something build-In function for that, like str2Date(Format).... but there is no such build-In function. Seem like Navision is very lacking of build in function for development. :(

    Anyway, thanks for all of you.
    Ken
  • Options
    kinekine Member Posts: 12,562
    It is nothing about lacking functionality, it is about date format, that is controlled through system settings, and if you need another format, you must change it... :-) it is simple task and do not need special function for that... keep C/AL functions simple... you have simple tools for complex things...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    Tim81Tim81 Member Posts: 68
    kenl wrote:
    Seem like Navision is very lacking of build in function for development. :(
    Sorry, but I had to laugh about that. Please imagine you have to write every database request by yourself (as: "SELECT * FROM table WHERE id=10000 ORDER BY sort") instead of creating a record var and using SETRANGE. I think there are many build in functions for development.
  • Options
    DenSterDenSter Member Posts: 8,304
    kenl wrote:
    <snip>
    ....I thought it should be something build-In function for that, like str2Date(Format).... but there is no such build-In function.
    .... </snip>
    DMY2DATE is one of those functions. Open the object browser (hit F5), scroll down to where it says SYSTEM, and click on 'Date' in the middle pane. You will find all sorts of built in date functions.
Sign In or Register to comment.