Type Conversion
gulamdastagir
Member Posts: 411
hello navies,
can you tell me how to convert a variable from
1. string into date
2.Code into Integer
thanks
can you tell me how to convert a variable from
1. string into date
2.Code into Integer
thanks
Regards,
GD
GD
0
Comments
-
Use EVALUATE:
1. EVALUATE(MyDate,MyString);
2. EVALUATE(MyInteger,MyCode);Timo Lässer
Microsoft Dynamics NAV Developer since 1997
MSDynamics.de - German Microsoft Dynamics Community - member of [clip]0 -
Hi,gulamdastagir wrote:can you tell me how to convert a variable from
1. string into date
2.Code into Integer
It depends on what string you're talking about. We had to write a utility codeunit in-house just to convert non-standard date strings as our vendors use different systems that will export very unconventional date strings and they also require data file with non-standard date strings (especially domestic road carriers like Toll and TNT). I pasted some code for your reference.NormalizeDateStr(DateStr : Text[1024];InputMask : Code[10]) : Text[30] IF (STRPOS(DateStr,'/') <> 0) THEN DateSeparator := '/'; IF (STRPOS(DateStr,'-') <> 0) THEN DateSeparator := '-'; IF (STRPOS(DateStr,'.') <> 0) THEN DateSeparator := '.'; DateSeparator1Pos := GetNextSeparatorPos(DateSeparator,DateStr); DateSeparator2Pos := GetNextSeparatorPos(DateSeparator,DateStr); CASE InputMask OF 'DDMMCCYY' : EXIT(COPYSTR(DateStr,1,2)+COPYSTR(DateStr,3,2)+COPYSTR(DateStr,7,2)); 'CCYYMMDD' : EXIT(COPYSTR(DateStr,7,2)+COPYSTR(DateStr,5,2)+COPYSTR(DateStr,3,2)); 'CCYYDDMM' : EXIT(COPYSTR(DateStr,5,2)+COPYSTR(DateStr,7,2)+COPYSTR(DateStr,3,2)); 'MMDDCCYY' : EXIT(COPYSTR(DateStr,3,2)+COPYSTR(DateStr,1,2)+COPYSTR(DateStr,5,2)); 'DDMMYY' : EXIT(COPYSTR(DateStr,1,2)+COPYSTR(DateStr,3,2)+COPYSTR(DateStr,5,2)); 'YYMMDD' : EXIT(COPYSTR(DateStr,5,2)+COPYSTR(DateStr,3,2)+COPYSTR(DateStr,1,2)); 'MMDDYY' : EXIT(COPYSTR(DateStr,3,2)+COPYSTR(DateStr,1,2)+COPYSTR(DateStr,5,2)); 'DD/MM/YY' : EXIT(PadLeft(COPYSTR(DateStr,1,DateSeparator1Pos-1),2,'0')+ PadLeft(COPYSTR(DateStr,DateSeparator1Pos+1,DateSeparator2Pos-1-DateSeparator1Pos),2,'0')+ COPYSTR(DateStr,DateSeparator2Pos+1,2)); 'DD/MM/CCYY' : EXIT(PadLeft(COPYSTR(DateStr,1,DateSeparator1Pos-1),2,'0')+ PadLeft(COPYSTR(DateStr,DateSeparator1Pos+1,DateSeparator2Pos-1-DateSeparator1Pos),2,'0')+ COPYSTR(DateStr,DateSeparator2Pos+3,2)); 'MM/DD/YY' : EXIT(PadLeft(COPYSTR(DateStr,DateSeparator1Pos+1,DateSeparator2Pos-1-DateSeparator1Pos),2,'0')+ PadLeft(COPYSTR(DateStr,1,DateSeparator1Pos-1),2,'0')+ COPYSTR(DateStr,DateSeparator2Pos+1,2)); 'MM/DD/CCYY' : EXIT(PadLeft(COPYSTR(DateStr,DateSeparator1Pos+1,DateSeparator2Pos-1-DateSeparator1Pos),2,'0')+ PadLeft(COPYSTR(DateStr,1,2),DateSeparator1Pos-1,'0')+ COPYSTR(DateStr,DateSeparator2Pos+3,2)); 'YY/MM/DD' : EXIT(PadLeft(COPYSTR(DateStr,DateSeparator2Pos+1,STRLEN(DateStr)-DateSeparator2Pos),2,'0')+ PadLeft(COPYSTR(DateStr,DateSeparator1Pos+1,DateSeparator2Pos-1-DateSeparator1Pos),2,'0')+ COPYSTR(DateStr,1,2)); 'CCYY/MM/DD' : EXIT(PadLeft(COPYSTR(DateStr,DateSeparator2Pos+1,STRLEN(DateStr)-DateSeparator2Pos),2,'0')+ PadLeft(COPYSTR(DateStr,DateSeparator1Pos+1,DateSeparator2Pos-1-DateSeparator1Pos),2,'0')+ COPYSTR(DateStr,3,2)); 'DD-MM-YY' : EXIT(PadLeft(COPYSTR(DateStr,1,DateSeparator1Pos-1),2,'0')+ PadLeft(COPYSTR(DateStr,DateSeparator1Pos+1,DateSeparator2Pos-1-DateSeparator1Pos),2,'0')+ COPYSTR(DateStr,DateSeparator2Pos+1,2)); 'DD-MM-CCYY' : EXIT(PadLeft(COPYSTR(DateStr,1,DateSeparator1Pos-1),2,'0')+ PadLeft(COPYSTR(DateStr,DateSeparator1Pos+1,DateSeparator2Pos-1-DateSeparator1Pos),2,'0')+ COPYSTR(DateStr,DateSeparator2Pos+3,2)); 'MM-DD-YY' : EXIT(PadLeft(COPYSTR(DateStr,DateSeparator1Pos+1,DateSeparator2Pos-1-DateSeparator1Pos),2,'0')+ PadLeft(COPYSTR(DateStr,1,DateSeparator1Pos-1),2,'0')+ COPYSTR(DateStr,DateSeparator2Pos+1,2)); 'MM-DD-CCYY' : EXIT(PadLeft(COPYSTR(DateStr,DateSeparator1Pos+1,DateSeparator2Pos-1-DateSeparator1Pos),2,'0')+ PadLeft(COPYSTR(DateStr,1,2),DateSeparator1Pos-1,'0')+ COPYSTR(DateStr,DateSeparator2Pos+3,2)); 'YY-MM-DD' : EXIT(PadLeft(COPYSTR(DateStr,DateSeparator2Pos+1,STRLEN(DateStr)-DateSeparator2Pos),2,'0')+ PadLeft(COPYSTR(DateStr,DateSeparator1Pos+1,DateSeparator2Pos-1-DateSeparator1Pos),2,'0')+ COPYSTR(DateStr,1,2)); 'CCYY-MM-DD' : EXIT(PadLeft(COPYSTR(DateStr,DateSeparator2Pos+1,STRLEN(DateStr)-DateSeparator2Pos),2,'0')+ PadLeft(COPYSTR(DateStr,DateSeparator1Pos+1,DateSeparator2Pos-1-DateSeparator1Pos),2,'0')+ COPYSTR(DateStr,3,2)); 'DD.MM.YY' : EXIT(PadLeft(COPYSTR(DateStr,1,DateSeparator1Pos-1),2,'0')+ PadLeft(COPYSTR(DateStr,DateSeparator1Pos+1,DateSeparator2Pos-1-DateSeparator1Pos),2,'0')+ COPYSTR(DateStr,DateSeparator2Pos+1,2)); 'DD.MM.CCYY' : EXIT(PadLeft(COPYSTR(DateStr,1,DateSeparator1Pos-1),2,'0')+ PadLeft(COPYSTR(DateStr,DateSeparator1Pos+1,DateSeparator2Pos-1-DateSeparator1Pos),2,'0')+ COPYSTR(DateStr,DateSeparator2Pos+3,2)); 'MM.DD.YY' : EXIT(PadLeft(COPYSTR(DateStr,DateSeparator1Pos+1,DateSeparator2Pos-1-DateSeparator1Pos),2,'0')+ PadLeft(COPYSTR(DateStr,1,DateSeparator1Pos-1),2,'0')+ COPYSTR(DateStr,DateSeparator2Pos+1,2)); 'MM.DD.CCYY' : EXIT(PadLeft(COPYSTR(DateStr,DateSeparator1Pos+1,DateSeparator2Pos-1-DateSeparator1Pos),2,'0')+ PadLeft(COPYSTR(DateStr,1,2),DateSeparator1Pos-1,'0')+ COPYSTR(DateStr,DateSeparator2Pos+3,2)); 'YY.MM.DD' : EXIT(PadLeft(COPYSTR(DateStr,DateSeparator2Pos+1,STRLEN(DateStr)-DateSeparator2Pos),2,'0')+ PadLeft(COPYSTR(DateStr,DateSeparator1Pos+1,DateSeparator2Pos-1-DateSeparator1Pos),2,'0')+ COPYSTR(DateStr,1,2)); 'CCYY.MM.DD' : EXIT(PadLeft(COPYSTR(DateStr,DateSeparator2Pos+1,STRLEN(DateStr)-DateSeparator2Pos),2,'0')+ PadLeft(COPYSTR(DateStr,DateSeparator1Pos+1,DateSeparator2Pos-1-DateSeparator1Pos),2,'0')+ COPYSTR(DateStr,3,2)); 'DD-MMM' : BEGIN Month := COPYSTR(UPPERCASE(DateStr),DateSeparator1Pos+1,3); CASE Month OF 'JAN' : Month := '01'; 'FEB' : Month := '02'; 'MAR' : Month := '03'; 'APR' : Month := '04'; 'MAY' : Month := '05'; 'JUN' : Month := '06'; 'JUL' : Month := '07'; 'AUG' : Month := '08'; 'SEP' : Month := '09'; 'OCT' : Month := '10'; 'NOV' : Month := '11'; 'DEC' : Month := '12'; END; Year := FORMAT(DATE2DMY(TODAY,3)); EXIT(PadLeft(COPYSTR(DateStr,1,2),2,'0')+ PadLeft(Month,2,'0')+ COPYSTR(Year,3,2)); END; 'DD-MMM-YY' : BEGIN Month := COPYSTR(UPPERCASE(DateStr),DateSeparator1Pos+1,3); CASE Month OF 'JAN' : Month := '01'; 'FEB' : Month := '02'; 'MAR' : Month := '03'; 'APR' : Month := '04'; 'MAY' : Month := '05'; 'JUN' : Month := '06'; 'JUL' : Month := '07'; 'AUG' : Month := '08'; 'SEP' : Month := '09'; 'OCT' : Month := '10'; 'NOV' : Month := '11'; 'DEC' : Month := '12'; END; EXIT(PadLeft(COPYSTR(DateStr,1,2),2,'0')+ PadLeft(Month,2,'0')+ COPYSTR(DateStr,8,2)); END; END; FormatDate(Date : Date;OutputMask : Text[30]) : Text[30] Day := PadLeft(FORMAT(DATE2DMY(Date,1)),2,'0'); Month := PadLeft(FORMAT(DATE2DMY(Date,2)),2,'0'); Year := PadLeft(FORMAT(DATE2DMY(Date,3)),4,'0'); CASE OutputMask OF 'DDMMCCYY' : EXIT(Day+Month+Year); 'CCYYMMDD' : EXIT(Year+Month+Day); 'MMDDCCYY' : EXIT(Month+Day+Year); 'DDMMYY' : EXIT(Day+Month+COPYSTR(Year,3,2)); 'YYMMDD' : EXIT(COPYSTR(Year,3,2)+Month+Day); 'MMDDYY' : EXIT(Month+Day+COPYSTR(Year,3,2)); 'DD/MM/CCYY' : EXIT(Day+'/'+Month+'/'+Year); 'CC/YY/MMDD' : EXIT(Year+'/'+Month+'/'+Day); 'MM/DD/CCYY' : EXIT(Month+'/'+Day+'/'+Year); 'DD/MM/YY' : EXIT(Day+'/'+Month+'/'+COPYSTR(Year,3,2)); 'YY/MM/DD' : EXIT(COPYSTR(Year,3,2)+'/'+Month+'/'+Day); 'MM/DD/YY' : EXIT(Month+'/'+Day+'/'+COPYSTR(Year,3,2)); 'DD-MM-CCYY' : EXIT(Day+'-'+Month+'-'+Year); 'CC-YY-MMDD' : EXIT(Year+'-'+Month+'-'+Day); 'MM-DD-CCYY' : EXIT(Month+'-'+Day+'-'+Year); 'DD-MM-YY' : EXIT(Day+'-'+Month+'-'+COPYSTR(Year,3,2)); 'YY-MM-DD' : EXIT(COPYSTR(Year,3,2)+'-'+Month+'-'+Day); 'MM-DD-YY' : EXIT(Month+'-'+Day+'-'+COPYSTR(Year,3,2)); END;0 -
How to increment a variable of type code:
eg varCode:=558 how do we make its value=559Regards,
GD0 -
NewString := INCSTR(String)
:oops:Regards,
GD0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 611 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 253 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
