Convert date format dd-mm-yyy to dd/mm/yyyy

Community Alums
Not applicable

Hi All,

having a requirement that need to convert the data format from dd-MM-yyyy to dd/MM/yyyy on the flow designer 

 

by the below script in the flow designer by flow variables 

 

var dt = gs.nowDateTime();

return dt.toString().split(" ")[0];
 
the out put i'm getting dd-MM-yyyy
 
need to get dd/MM/yyyy
 
 
any suggestions. 
2 ACCEPTED SOLUTIONS

jMarshal
Mega Sage
Mega Sage
You're almost there...just gotta do another split and replace the "-" with "/"

var
 dt = gs.nowDateTime();
dt = dt.toString().split(" ")[0];

 

var parts = dt.split('-');
var day = parts[0];
var month = parts[1];
var year = parts[2];

 

var formattedDate = day + '/' + month + '/' + year;

 

return formattedDate;

View solution in original post

Community Alums
Not applicable

Hi @jMarshal 

 

The script you suggested is working 

var gd =new GlideDate();
var dt = gs.nowDateTime();
dt = dt.toString().split(" ")[0];
var parts = dt.split('-');
var day = parts[0];
var month = gd.getMonth();
month = month.toString();
month = "0" + month;
month = month.slice(-2);
var year = gd.getYear();
var formattedDate = day + '/' + month + '/' + year;
return formattedDate;

 

in the above script i changed for year then it completely retrieving the value as required 

20/06/2023. 

 

Thank You @jMarshal .

View solution in original post

8 REPLIES 8


I think this has to do with your default date format on your instance...by default, "getMonth()" returns a numerical value for the current month, if you have a different setting, it might be conflicting - which is why you see "NaN" (Not a Number).

You can try this...it might work:

var gd =new GlideDate();

 

var dt = gs.nowDateTime();


dt = dt.toString().split(" ")[0];

 

var parts = dt.split('-');
var day = parts[0];
var month = gd.getMonth();
var year = parts[2];

 

var formattedDate = day + '/' + month + '/' + year;

 

return formattedDate;

Community Alums
Not applicable

Hi @jMarshal 

 

we are almost there, 

chanti1_0-1687242544932.png

 

the current date is populating but required some changes on the month and the year.

 

we need to populate date dd- 20 , MM- 06 - year - 2023

i.e,. 20/06/2023

 

 

any suggestions.

 


OK - how about this...?

var gd =new GlideDate();

var dt = gs.nowDateTime();

 

dt = dt.toString().split(" ")[0];

 

var parts = dt.split('-');
var day = parts[0];
var month = gd.getMonth();

 

month = month.toString();

month = "0" + month;

month = month.slice(-2);


var year = parts[2];

var formattedDate = day + '/' + month + '/' + year;

 

return formattedDate;

Community Alums
Not applicable

Hi @jMarshal 

 

The script you suggested is working 

var gd =new GlideDate();
var dt = gs.nowDateTime();
dt = dt.toString().split(" ")[0];
var parts = dt.split('-');
var day = parts[0];
var month = gd.getMonth();
month = month.toString();
month = "0" + month;
month = month.slice(-2);
var year = gd.getYear();
var formattedDate = day + '/' + month + '/' + year;
return formattedDate;

 

in the above script i changed for year then it completely retrieving the value as required 

20/06/2023. 

 

Thank You @jMarshal .