Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

NAV reading wrong/Junk value for Time column in Excel.

(0) ShareShare
ReportReport
Posted on by 171

Hey,

I am reading a fetching data from excel and dumping in NAV table using Automation variable.

The issue is NAV is reading incorrect time value from Excel.

Below is example of my code:

-------------------------------------------------Code----------------------------------------------------
FileName := 'D:\GRN_Today.xlsx';
CLEAR(ExcelApp);
CLEAR(ExcelWorkSheet);
CLEAR(ExcelWrkbook);
i := 0;
IF NOT CREATE(ExcelApp,TRUE,TRUE) THEN
  ERROR('Error');
ExcelWrkbook := ExcelApp.Workbooks.Open(FileName);
ExcelWorkSheet := ExcelWrkbook.ActiveSheet;

i := 2;
REPEAT
  PODate := FORMAT(ExcelWorkSheet.Range('Q'+FORMAT(i)).Value);                              // PO Date
  DeliveredTime := FORMAT(ExcelWorkSheet.Range('R'+FORMAT(i)).Value);                       // Delivered Time
  CreatedTime := FORMAT(ExcelWorkSheet.Range('S'+FORMAT(i)).Value);                         // Created Time

  //MESSAGE('PO Date: '+PODate);
  MESSAGE('Del Time: '+DeliveredTime);
  MESSAGE('CreatedTime: '+CreatedTime);
  i+=1;
UNTIL FORMAT(ExcelWorkSheet.Range('A'+FORMAT(i)).Value) = '';

ExcelWrkbook.Close;
ExcelApp.Quit;
CLEAR(ExcelWorkSheet);
CLEAR(ExcelWrkbook);
CLEAR(ExcelApp);

---------------------------------------------------Code--------------------------------------------------

The variables 'ExcelWorkSheet', 'ExcelWrkbook' and 'ExcelApp' are office automation variables

The variables 'DeliveredTime', 'CreatedTime' and 'PODate' are text variables.

I've even tried changing the format in excel, but all in vain.

The output for time value is

1

---------------------------
Microsoft Dynamics NAV Classic
---------------------------
Del Time: 42,816.705555555556
---------------------------
OK   
---------------------------

2

---------------------------
Microsoft Dynamics NAV Classic
---------------------------
CreatedTime: 0.41175925925925921
---------------------------
OK   
---------------------------


even though the value in excel is time : 09:52:56

I've found one link but that seems only to be a workaround but doesn't looks like a solution.

https://dynamicsuser.net/nav/f/developers/8625/importing-a-time-field-from-excel

Please let me know, if anybody have solved such issue.

*This post is locked for comments

  • Verified answer
    Prtham Profile Picture
    Prtham 171 on at
    RE: NAV reading wrong/Junk value for Time column in Excel.

    I found a solution using above link. Posting it for other who face the problem:

    FileName := 'D:\GRN_Today.xlsx';
    
    CLEAR(ExcelApp);
    CLEAR(ExcelWorkSheet);
    CLEAR(ExcelWrkbook);
    i := 0;
    
    IF NOT CREATE(ExcelApp,TRUE,TRUE) THEN
      ERROR('Error');
    ExcelWrkbook := ExcelApp.Workbooks.Open(FileName);
    ExcelWorkSheet := ExcelWrkbook.ActiveSheet;
    
    i := 2;
    REPEAT
      PODate := FORMAT(ExcelWorkSheet.Range('W'+FORMAT(i)).Value);
      DeliveredTime2 := ConvertTime(FORMAT(ExcelWorkSheet.Range('R'+FORMAT(i)).Value));
      CreatedTime2 := ConvertTime(FORMAT(ExcelWorkSheet.Range('S'+FORMAT(i)).Value));
      MESSAGE('Time Del :'+ FORMAT(DeliveredTime2));
      MESSAGE('Time CreatedTime :'+FORMAT(CreatedTime2));
    
      i+=1;
    UNTIL FORMAT(ExcelWorkSheet.Range('A'+FORMAT(i)).Value) = '';
    
    ExcelWrkbook.Close;
    ExcelApp.Visible := FALSE;
    ExcelApp.Quit;
    CLEAR(ExcelWorkSheet);
    CLEAR(ExcelWrkbook);
    CLEAR(ExcelApp);
    


    And the defination of function: ConvertTime(text):Time

    ConvertTime(DecimalTimeText : Text[50]) : Time
    //DeliveredTime := FORMAT(ExcelWorkSheet.Range('R'+FORMAT(i)).Value);                       // Delivered Time
    EVALUATE(DeliveredTime_Decimal,DecimalTimeText);
    IF DeliveredTime_Decimal > 0 THEN BEGIN
    DeliveredTime_Decimal := DeliveredTime_Decimal*24;
    HH:= ROUND(DeliveredTime_Decimal,1,'<');
    DeliveredTime_Decimal := DeliveredTime_Decimal-HH;
    DeliveredTime_Decimal := DeliveredTime_Decimal*60;
    MM := ROUND(DeliveredTime_Decimal,1,'<');
    DeliveredTime_Decimal := DeliveredTime_Decimal - MM;
    DeliveredTime_Decimal := DeliveredTime_Decimal*60;
    SS := ROUND(DeliveredTime_Decimal,1,'=');
      EVALUATE(DeliveredTime2,FORMAT(HH)+':'+FORMAT(MM)+':'+FORMAT(SS));
    END ELSE  
      DeliveredTime2 := 0T;
      
    EXIT(DeliveredTime2);
    


    Till now giving exact time output. Let me know, if anyone finds a bug in it.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans