Sorting Dataset in Repeater Based on DateField Input

Hello again… another road block, thanks for all the support so far.

I have a repeater linked to a dataset which has fields such as
Name
Email
Date Created
Date of Service

The Date of Service field is currently set to “Date” type and it receives it’s input from a form that the customer fills in using a date selector.

The values save like this

Date of Service:
Mar 31, 2023
Jan 1, 2024
Jul 9, 2023

etc.

I have tried using the sort function on the dataset “From old to new” which doesn’t seem to work.
I have also tried using code with the setSort() function and .ascending but this lists it in alphabetical order not in order of date.

Any ideas or resources that can help me with this?

Many thanks

This is what i came up with using the month as the filter… it’s a lot of code, any ideas how i can make it more efficient?



function startDate (){

if(todaysDate.toString().includes("Mar")){
dateNumber = 3;
console.log (dateNumber)}

if(todaysDate.toString().includes("Jan")){
dateNumber = 1;
console.log (dateNumber)}

if(todaysDate.toString().includes("Feb")){
dateNumber = 2;
console.log (dateNumber)}

if(todaysDate.toString().includes("Apr")){
dateNumber = 4;
console.log (dateNumber)}

if(todaysDate.toString().includes("May")){
dateNumber = 5;
console.log (dateNumber)}

if(todaysDate.toString().includes("Jun")){
dateNumber = 6;
console.log (dateNumber)}

if(todaysDate.toString().includes("Jul")){
dateNumber = 7;
console.log (dateNumber)}

if(todaysDate.toString().includes("Aug")){
dateNumber = 8;
console.log (dateNumber)}

if(todaysDate.toString().includes("Sep")){
dateNumber = 9;
console.log (dateNumber)}

if(todaysDate.toString().includes("Oct")){
dateNumber = 10;
console.log (dateNumber)}

if(todaysDate.toString().includes("Nov")){
dateNumber = 11;
console.log (dateNumber)}

if(todaysDate.toString().includes("Dec")){
dateNumber = 12;
console.log (dateNumber)}

filterStuff()
} //end ifs, begining date is done

function thenFilterbyDate(){
  console.log ("you are in the filter function by month now" + " the month number is: " + dateNumber)
  
  if(dateNumber == 1){ 
      $w('#bookingsText').text = "January"
      $w('#dataset2').setFilter(wixData.filter()
      .contains("dateField", "Jan")
  )}

  if(dateNumber == 2){ 
    $w('#bookingsText').text = "February"
      $w('#dataset2').setFilter(wixData.filter()
      .contains("dateField", "Feb")
  )}

  if(dateNumber == 3){ 
    $w('#bookingsText').text = "March"
      $w('#dataset2').setFilter(wixData.filter()
      .contains("dateField", "Mar")
  )}

  if(dateNumber == 4){ 
    $w('#bookingsText').text = "April"
      $w('#dataset2').setFilter(wixData.filter()
      .contains("dateField", "Apr")
  )}

    if(dateNumber == 5){ 
      $w('#bookingsText').text = "May"
      $w('#dataset2').setFilter(wixData.filter()
      .contains("dateField", "May")
  )}

    if(dateNumber == 6){ 
      $w('#bookingsText').text = "June"
      $w('#dataset2').setFilter(wixData.filter()
      .contains("dateField", "Jun")
  )}

    if(dateNumber == 7){ 
      $w('#bookingsText').text = "July"
      $w('#dataset2').setFilter(wixData.filter()
      .contains("dateField", "Jul")
  )}

    if(dateNumber == 8){ 
      $w('#bookingsText').text = "August"
      $w('#dataset2').setFilter(wixData.filter()
      .contains("dateField", "Aug")
  )}

    if(dateNumber == 9){ 
      $w('#bookingsText').text = "September"
      $w('#dataset2').setFilter(wixData.filter()
      .contains("dateField", "Sep")
  )}

    if(dateNumber == 10){ 
      $w('#bookingsText').text = "Octomber"
      $w('#dataset2').setFilter(wixData.filter()
      .contains("dateField", "Oct")
  )}

    if(dateNumber == 11){ 
      $w('#bookingsText').text = "November"
      $w('#dataset2').setFilter(wixData.filter()
      .contains("dateField", "Nov")
  )}

    if(dateNumber == 12){ 
      $w('#bookingsText').text = "December"
      $w('#dataset2').setFilter(wixData.filter()
      .contains("dateField", "Dec")
  )}
}

$w('#nextMonth').onClick(function(){
  dateNumber = Number(dateNumber) + 1
  console.log ("Current date number is: " + dateNumber)
  thenFilterbyDate()
})

$w('#prevMonth').onClick(function() {
  dateNumber = Number(dateNumber) - 1
  console.log ("Current date number is: " + dateNumber)
  thenFilterbyDate()
})