1

referring to this link:https://clarity.design/documentation/datepicker in the last section titled Summary of Options, it states that, for example, [max] should be in YYYY-MM-DD formate.

as shown in the below posted code, i set the same format to maxDateLimit. but when run the code, i receive the logs shown in the screen-shot.

Am I using YYYY-MM-DD wongly? please let me know why i am getting this error and how to fix it

code:

private onSatelliteTimeRangeFromSet(event:any):void {
console.log(this.debugTag,"dateOfSpray: ", this.iDatePasser.dateOfSpray)
const splitted = this.iDatePasser.dateOfSpray.split('/')
const numOfDateBites = splitted.length
this.maxDateLimit = this.datePipe.transform(new Date(), 'YYYY-MM-DD') as string
const maxDateLimitAsDate = new Date(this.maxDateLimit)
const dateOfSprayAsDate = new Date(this.iDatePasser.dateOfSpray)
const maxDateDate = maxDateLimitAsDate.getDate()
const maxDateMonth = maxDateLimitAsDate.getMonth()
const maxDateYear = maxDateLimitAsDate.getFullYear()

console.log(this.debugTag,"maxDateLimit: ", this.maxDateLimit)

logs

enter image description here

JSON Derulo
  • 9,780
  • 7
  • 39
  • 56
Amrmsmb
  • 1
  • 27
  • 104
  • 226
  • 1
    In the [docs related](https://angular.io/api/common/DatePipe#custom-format-options) you see the "custom format options". See that year are `yyyy` and day `dd` (both in lowercase). In the clarity doc's only say that you need use a string with the fullYear, the month and the day of the month. – Eliseo Aug 11 '23 at 06:19
  • 1
    NOTE: From Angular 12, you can use the formatDate function directly: `this.maxDateLimit = formatDate(new Date(), 'yyy-MM-dd','en-US')`, see this [SO](https://stackoverflow.com/questions/76873436/how-to-prevent-selection-of-date-values-beyond-todays-date/76873888#76873888) – Eliseo Aug 11 '23 at 06:20

3 Answers3

1

Please refer to the issue below.

Try lowercase yyyy rather than uppercase YYYY?

how to convert current date to YYYY-MM-DD format with angular 2

1

There are 2 issues :

  • You're using YYYY which is the "week numbering year", you need to use yyyy

  • DD has no value, you need to use dd to get the date.

Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134
0

try this

  1. DD to dd (small)
  2. YYYY to yyyy (small)