# Date Hell

**URL:** <https://community.glideapps.com/t/date-hell/31031>\
**Category:** Ask for Help\
**Tags:** custom-code\
**Created:** [August 27, 2021, 11:42am UTC](https://community.glideapps.com/t/date-hell/31031 "2021-08-27T11:42:47Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)\
**Post date:** [August 27, 2021, 10:48pm UTC](https://community.glideapps.com/t/date-hell/31031/7 "2021-08-27T22:48:44Z")

</div>

Hola @Manu.n

it’s my code so far to sort and return a Date array (ascending) when a user has the date format **dd/mm/yyyy**.

It sorts the date and time at the same time and needs a date array of course to work.  
In my case, I use a Hell Yes-Code version (from Mark’s version) where **p8 parameter** is the original (raw) Date Array:

```auto
p8.sort(function (a, b) {
  // '13/9/2021 12:00:20'.split(' ') => ["13/9/2021", "12:00:20"]
  let DTa = a.split(' '); DTb = b.split(' ');

  // '13/9/2021'.split('/') => ["13", "9", "2021"]
  let da = DTa[0].split('/');
  let db = DTb[0].split('/');

  let HMSa=DTa[1].split(':');
  let HMSb=DTb[1].split(':');

  // Hour
  let ha = HMSa[0]; 
  let hb = HMSb[0];
 
  // Minute
  let ma = HMSa[1]; 
  let mb = HMSb[1];

  // Secs
  let sa = HMSa[2]; 
  let sb = HMSb[2];

  return da[2] - db[2] || da[1] - db[1] ||  
             da[0] - db[0] || ha - hb || 
              ma - mb || sa - sb 
});
 
 // return the new sorted array
 return p8

```

My replit URL is:  
[https://Array-YesCode.gustavovalero.repl.co](https://Array-YesCode.gustavovalero.repl.co)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/a/c/ac87cdec5bf9b8a89baf4d59880abc80dbf37d84.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/b/3/b3af2a70af26f9c6b3f8edd35e2e1db0bf3634ba.png)

Saludos!

---

_[View the full topic](https://community.glideapps.com/t/date-hell/31031)._
