Grid type: date - unable to get format correctly

I have a date column that i had noticed would not sort correctly because it was by default a string. However I tried to use the format feature and it works for the day and year but changes the month all to first month

date format/output should be for example: 03/23/2020

The following:

columns: [ { width: 150, id: "my_id", header: [{ text: "Date" },{ content: "inputFilter" }],type: "date", format: "%m/%d/%Y" } ]

outputs: 01/23/2020

the day and year is good but i cannot figure out what i missing for the month

also, i presume format is necessary as i’ve tried just type: “date” w/ no luck

Please advise - thanks!

I am using your code and I’m finding a problem with the ‘/’ formatting. Are you sure this is working on your end? Here is a snippet using your code. If you place the ‘/’ (forward-slash) between the date codes, the script fails.
https://snippet.dhtmlx.com/yz7rp2f9

Hey ND,

Thanks for the try…my date format is: “Month/Day/Year”…your code is not prepared for that data and probably is why it’s getting the error…

I did find the issue…below are 2 sets of data …

  1. dataset has date where can be single digit day or month and that is what’s making it not work with the format “%m/%/d%Y”

  2. dataset_02 does work with the format “%m/%/d%Y”

So I can manipulate the date on the backend before processed by javascript or is there a format that will work with a date that can have a single digit day or month?

Thanks!

<script>

    const dataset = 
     [
       {"first_discovered":"4/13/2022","last_discovered":"4/13/2022"},
       {"first_discovered":"7/13/2020","last_discovered":"4/13/2022"},
       {"first_discovered":"4/13/2022","last_discovered":"4/13/2022"},
       {"first_discovered":"6/25/2021","last_discovered":"4/13/2022"},
       {"first_discovered":"3/30/2022","last_discovered":"4/13/2022"},
       {"first_discovered":"2/13/2018","last_discovered":"4/13/2022"}     
  
     ]


    const dataset_02 = 
     [
       {"first_discovered":"04/13/2022","last_discovered":"04/13/2022"},
       {"first_discovered":"07/13/2020","last_discovered":"04/13/2022"},
       {"first_discovered":"04/13/2022","last_discovered":"04/13/2022"},
       {"first_discovered":"06/25/2021","last_discovered":"04/13/2022"},
       {"first_discovered":"03/30/2022","last_discovered":"04/13/2022"},
       {"first_discovered":"02/13/2018","last_discovered":"04/13/2022"}     
  
     ]

const grid = new dhx.Grid("grid", {
    columns: [ 
              { width: 150, id: "first_discovered", header: [{ text: "First Discovered" }, { content: "inputFilter" }],type: "date", format: "%m/%d/%Y" },
              { width: 150, id: "last_discovered",  header: [{ text: "Last Discovered" },{ content: "inputFilter" }],type: "date", format: "%m/%d/%Y" }                
             ],

    data: dataset_02
  
    
 });

</script>

If a month is defined without a leading zero it should be defined as “%n” in your date format:
https://snippet.dhtmlx.com/i84yyu9y
The template can be found here:
https://docs.dhtmlx.com/suite/calendar/api/calendar_dateformat_config/
Please, try to use the date format corresponding to the used one in your data