How can i convert date format at client side

saint
Tera Expert

Hi Experts 

by using new Date() at client side I'm getting the currrent date

saint_0-1687515622656.png

 

and a UI page date select field is giving me this value

saint_1-1687515678052.png

 

Now I want to compare the selected value with current value to show user a message to change the date to a future date. Server vaidation is present but I need a client popup msg, so they can update the value/ or know why the server did not enter the record as it goes with screen reload.

 

Please let me know how can I convert 1st value (i.e current date to 2nd date format for validation)

 

Regards,

 

1 ACCEPTED SOLUTION

Karan Chhabra6
Mega Sage
Mega Sage

Hi @saint ,

 

Please use the following code to convert the date to yyyy-mm-dd format

var date = new Date();
var d = date.toISOString().split('T')[0];
alert(d);

 

Output:

KaranChhabra6_0-1687519287099.png

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!

 

View solution in original post

2 REPLIES 2

MattSN
Mega Sage
Mega Sage

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date 

In your brower console run this to see an example

var date = new Date();
date.toDateString();

 

Karan Chhabra6
Mega Sage
Mega Sage

Hi @saint ,

 

Please use the following code to convert the date to yyyy-mm-dd format

var date = new Date();
var d = date.toISOString().split('T')[0];
alert(d);

 

Output:

KaranChhabra6_0-1687519287099.png

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!