Text Input Format

I have a date that I am bringing in from localStorage onto a Text input field but unfortunately the date string includes a time stamp when all I need is the date.

Is there some way of formatting the text input field so it will show Date only.

I am including some screen shots for detail.

Mike

This shows the Test Input field
PrintScreen02

This shows my attempt at formatting at the bottom which has not worked.

Hi @mdsmith1, if you only need the date we can use "moment.js" to format it. We could do it directly on the input, but it would be a better idea to do it before we add it to localStorage. Could you share how this date is getting to localStorage?

Let's say you have a JS query that does:

const date = new Date();
localStorage.setItem('mPaidDate', date);

Instead, format it before adding it:

const date = new Date();
const formattedDate = moment(date).format('MM-DD-YYYY'); // format date
localStorage.setItem('mPaidDate', formattedDate);

I have tried this and have an error message as below:

Mike

I apologize, "setITem" is the native JS syntax. In Retool we must use setValue:

const date = new Date();
const formattedDate = moment(date).format('MM-DD-YYYY'); // format date
localStorage.setValue('mPaidDate', formattedDate);
1 Like

Paulo:

Yes, it worked!

Thank you so much.

I will mark it as a solution.

Thanks again.

Mike

1 Like

You are welcome! :slightly_smiling_face: