How to show Datetime dates should start from Today Dates.Before dates from today should disable.

How to show Datetime dates should start from Today Dates.Before dates from today should disable.

OmniwyseOmniwyse Posts: 29Questions: 11Answers: 0

I want to have the datetime should be start from today's date earlier date should be grey out.
Example : Yesterday and earlier dates should be grey out.
How to do that ?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,531Questions: 1Answers: 10,474 Site admin

    Use the minDate option of the datetime field type - e.g.:

    {
      label: 'My date:',
      name: 'date',
      opts: {
        minDate: new Date()
      }
    }
    

    Allan

  • OmniwyseOmniwyse Posts: 29Questions: 11Answers: 0

    Thank Allan for quick reply,

    I have added minDate to my date field, Now from Tomorrow onwards I am able to select the date from date picker. But the problem is todays date not able to select from date picker.Actually We should be select from todays date onwards right.

    Earlier dates are disables properly. Only the problem I am not able to select todays date only.

    This is how I added.
    {
    label: "Holiday Date :",
    name: "stringDate",
    data: "stringDate",
    type: "datetime",
    opts: {
    minDate: new Date()
    },
    displayFormat: "yyyy-MM-DD",
    wireFormat: "yyyy-MM-DD"
    },

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    You can jiggle that new date to remove a day from it, with

    minDate: new Date(Date.now() - ( 3600 * 1000 * 24))
    

    Please see example here,

    Colin

  • allanallan Posts: 63,531Questions: 1Answers: 10,474 Site admin

    Good catch - and thank you Colin for explaining how to resolve it!

    I thought it would be worth writing down here why that is happening (which I've just realised after reading your reply!) - new Date() will create a Date object at the current time - for me that is 14th Sept 2022 08:28:23 at this very moment. DateTime uses 00:00:00 as the time for its calculation base, thus that value is not <= now. Doh. Colin's fix works around that.

    Allan

  • OmniwyseOmniwyse Posts: 29Questions: 11Answers: 0

    Thank Colin and Allan :)

Sign In or Register to comment.