Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: MDB Date picker - date format help

MPL premium asked 1 year ago


Hi all I have the following date picker on my site:

        <mdb-form-control>
      <input
        mdbInput
        [mdbDatepicker]="datepicker"
        type="text"
        class="form-control"
        id="exampleDatepicker"
        [(ngModel)]="selectedDate"
        (change)="changeDate(); calcNight()"
        placeholder="dd/mm/yyyy"

      />
      <label mdbLabel for="exampleDatepicker" class="form-label">Select a date</label>
      <mdb-datepicker-toggle [mdbDatepicker]="datepicker"></mdb-datepicker-toggle>
      <mdb-datepicker   [inline]="true" #datepicker (dateChanged)="dateChange($event)"></mdb-datepicker>
    </mdb-form-control>

I am based in the UK and when I change the date I get the output eg Fri Jan 06 2023 02:35:19 GMT+0000 (Greenwich Mean Time) and here we use the format dd/mm/yyyy

Now a user of my site from the US has reported a problem where he entered the date in the format of mm/dd/yyyy but the picker translated it as a uk format dd/mm/yyyy. I am wondering how I and set the input format so the picker knows the format of the input and therefore gives the correct selectedDate?

Thanks for any help here


Rafał Seifert free answered 1 year ago


Please take a look at our datepicker docs section. We have format input which default value is 'dd/mm/yyyy'. You can change it according to your needs ( [format]="'mm,dd,yyyy'")

I hope that it solves your problem.



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Premium
  • Premium support: Yes
  • Technology: MDB Angular
  • MDB Version: MDB5 3.0.1
  • Device: Laptop
  • Browser: All
  • OS: Linux
  • Provided sample code: No
  • Provided link: No