Search code examples
backendstrapi

How to disable past dates with Strapi (Backend)


Do you have any tips how can I disable the past dates on input date for forms with Strapi (only backend, not frontend). I don't have any exact idea and I'm looking for an answer. Thanks in advance.


Solution

  • Compare the data.createdAt object field with the current time, which you can get by constructing a new Date object.

    const createdDate = new Date(data.createdAt);
    const currentDate = new Date():
    
    if(createdDate.getTime() < currentDate.getTime()) {
     // do something
    };