Search code examples
timetype-conversionaxaptadynamics-ax-2012x++

How to convert the string to TimeHour24?


I have to populate by code a Table Field. The table filed having a EDT TimeHour24. Field Timehour24

My String is like "05:30:15" I have to convert the string to EDT TimeHour24.

I used the function str2time but it is not useful.

How can I import and fill the field?

Thanks all


Solution

  • I think you should try again with str2time
    For a test I just created a simple table with one field of the EDT TimeHour24 and filled it with the job below.
    See the screenshot with the desired result as far as I understood the problem

    static void TimeTest(Args _args)
    {
        TimeTest tb;
        ;
    
        tb.TimeHour24 = str2time("05:30:15");
        tb.write();
    }
    

    Screenshot of working example

    I could imagine that you dumped the converted result to the infolog and saw a large integer and therefore thought it is not correct.
    The result of the conversion is the time in seconds and is how it is internally stored in the database behind the scenes.
    AX just displays the value in a human-readable way.