Sort by referenced journal date

I have an advanced query currently to list classes pages related to the current page (that is the course page) by a tag that has the link created with the datepicker. But I notice that the sorting is currently not sorting properly, because it’s not putting the months in an ascending order. How can I change my query to sort the pages properly?

  query-properties:: [:page :date :teacher :tecnologies]
  query-sort-by:: date
  query-sort-desc:: false
  #+BEGIN_QUERY
  { 
  :title [ :h1 "Classes" ]
  :query [
  :find (pull ?p [*])
  :in $ ?current
  :where
  [?p :block/name ?pname]
  [?t :block/name ?current]
  [?t :block/original-name ?original-current]
  (page-property ?p :course ?original-current)
  (page-property ?p :type "class")
  ]
  :inputs [:current-page]
  }
  #+END_QUERY

We need to sneak in an extra property and sort by that. (Can keep this property hidden, just showing to let you see)

See if this works for you.

#+BEGIN_QUERY
  { 
  :title [ :h1 "Classes" ]
  :query [
  :find ?day (pull ?p [*]) ;also return the day for sorting 
  :keys day page
  :in $ ?current
  :where
  [?p :block/name ?pname]
  [?t :block/name ?current]
  [?t :block/original-name ?original-current]
  (page-property ?p :course ?original-current)
  (page-property ?p :type "class")
  [?b :block/page ?p] ;get block on class page
  [?b :block/properties ?prop] ;that has properties
  [(get ?prop :date) ?date] ;get the value for the date property
  [?b :block/refs ?j] ;the block references ?j
  [?j :block/journal-day ?day] ;?j is defined as a journal page with a date
  [?j :block/original-name ?journal] ;the original name of the date
  [(contains? ?date ?journal)] ;is the same as the date in the property value. For safety, should you reference journal pages in the same block in a different property, or no property at all.
  ]
  :inputs [:current-page]
 :result-transform (fn [result] 
    (map 
      (fn [m] 
        (update (:page m) :block/properties 
          (fn [u] (assoc u :day (get-in m [:day]) ) )
        )
	  ) 
      result
    )
)
  }
  #+END_QUERY

Thanks @Siferiax your solution works perfectly!