Format date yyyy-MM-dd

poppinspoppins Member Posts: 647
edited 2015-06-23 in NAV Three Tier
Hi everyone,

I need to format a date into yyyy-MM-dd, for example 2015-06-22.
I tried the following:
FORMAT(date,0,'<Year4><Month,2><Day,2>')
But I got 20150622 as a result.

I tried the following:
FORMAT(date,0,'<Year4>-<Month,2>-<Day,2>')
but I got 22/06/2015 as a result.

What shall I do?
Thanks in advance :mrgreen:

Comments

  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    Try this:
    FORMAT(date,0,9);
    
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • poppinspoppins Member Posts: 647
    Try this:
    FORMAT(date,0,9);
    
    Just tried it but got 22/06/2015 as a result :mrgreen:
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    What version of NAV are you using? In NAV 2015, the code
    MESSAGE(FORMAT(TODAY,0,9));
    
    returns
    2015-06-22
    .
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • poppinspoppins Member Posts: 647
    What version of NAV are you using? In NAV 2015, the code
    MESSAGE(FORMAT(TODAY,0,9));
    
    returns
    2015-06-22
    .
    I am using NAV 2013.
    You're right, the message returns 2015-06-22 but when I write it to my .csv file, I get 22/06/2015 :mrgreen:
  • JonasAJonasA Member Posts: 28
    I just tried this and I got '2015-06-23' using the following code (Using Dynamics NAV 2015 CU3):

    Variables:
    File = File
    OutStream = OutStream
    
    File.CREATE('c:\temp\data.csv');
    File.CREATEOUTSTREAM(OutStream);
    OutStream.WRITETEXT(FORMAT(TODAY, 0, 9));
    File.CLOSE;
    
  • raaraa Member Posts: 1
    poppins wrote:
    What version of NAV are you using? In NAV 2015, the code
    MESSAGE(FORMAT(TODAY,0,9));
    
    returns
    2015-06-22
    .
    I am using NAV 2013.
    You're right, the message returns 2015-06-22 but when I write it to my .csv file, I get 22/06/2015 :mrgreen:

    Is the date formatted in the same way if you open your .csv file in a text editor instead of Excel, for example Notepad.
    Excel usually convert fields to local format if it is able to guess the data type.
Sign In or Register to comment.