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

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;

Community Alums
Not applicable

Hi @jMarshal 

 

The date format is coming up but its in 16/Jun/23

 

need to get the value like 16/06/2023.. 

 

any suggestions.

yup try this instead --- replacing the month from the parsed values with the numerical value:



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

 

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

 

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

 

return formattedDate;

 

Community Alums
Not applicable

Hi @jMarshal 

 

tried as you suggested but not able to retrieve the value result as below 

chanti1_0-1687201048606.png

 

need to get the date value in the format 19/06/2023.

 

tried another way but its not working.

 

var gd = new GlideDate();
return gd.getByFormat('dd/MM/yyy');
 
any other way to achieve this.