0

I am quite new to playwright and I'm struggling to find a solution on how I can populate a value with an automatically adjusting date stamp.

Does anyone know a way I can have it automatically populate with the current date, in the yyyy/mm/dd format, plus an extra day?

This is the command line for populating it with a fixed value:

await page.locator('input[type="date"]').fill('2023-01-20');

I'm guessing the .fill() will need a different line in there, but I'm just not sure how to do it.

Must be a date stamp without the time, so Date.now() for example does not work.

I've seen that the following is potentially a simple solution to my problem:

var date = new Date();
date.setDate(date.getDate() + 1);

But how would incorporate that into this line?

await page.locator('input[type="date"]').fill('2023-01-20');

Not sure why this was closed, I've found no answer to my question in other people's questions. I'm not trying to convert the format, i'm trying to input the date +1 day into my code. And yes this is in playwright.

apw2
  • 1
  • 1
  • This seems unrelated to Playwright (although the context is nice). It seems you want to [convert a Date object to yyyy-mm-dd format](https://stackoverflow.com/questions/23593052/format-javascript-date-as-yyyy-mm-dd). – ggorlen Jan 19 '23 at 20:14
  • This is actually something I am doing within playwright, but I don't know how to input the date within my line. It's not to do with the format of the date, just want it to auto use the current date + 1 day. – apw2 Jan 20 '23 at 15:07
  • You [already did current date + 1 day](https://stackoverflow.com/a/9989458/6243352), and Playwright's `.fill()` is just any old function call, so use `.fill(date.toISOString().split('T')[0])` where `date` is from the code you already have. – ggorlen Jan 20 '23 at 16:08

0 Answers0