# BUG: result as 'date-time' is not returned

**URL:** <https://community.glideapps.com/t/bug-result-as-date-time-is-not-returned/31345>\
**Category:** Ask for Help\
**Tags:** custom-code\
**Created:** [September 3, 2021, 11:19pm UTC](https://community.glideapps.com/t/bug-result-as-date-time-is-not-returned/31345 "2021-09-03T23:19:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maxim\_KM](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maxim_km/32/29274_2.png) [@Maxim\_KM](https://community.glideapps.com/u/Maxim_KM)\
**Post date:** [September 3, 2021, 11:19pm UTC](https://community.glideapps.com/t/bug-result-as-date-time-is-not-returned/31345/1 "2021-09-03T23:19:21Z")

</div>

I have a function that should return Date Time for further sort. It never returns the value. I’ve dug and cannot find anything. In addition, the documentation doesn’t have examples where the result will be ‘date-time’.  
But even with a dead simple function - the result is blank:

```auto
window.function = function () {
  return new Date()
}

```

glide.json:

```auto
    "result": {
      "type": "date-time"
    }

```

How it looks in GDE:

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

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [September 3, 2021, 11:40pm UTC](https://community.glideapps.com/t/bug-result-as-date-time-is-not-returned/31345/2 "2021-09-03T23:40:55Z")

</div>

Any thoughts @Manu.n @gvalero? I don’t use date-time that much in Replit. Seeing as you guys have worked with this a lot this week hopefully you have an answer.

---

<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:** [September 4, 2021, 12:32am UTC](https://community.glideapps.com/t/bug-result-as-date-time-is-not-returned/31345/3 "2021-09-04T00:32:23Z")

</div>

Hola @Maxim_KM

Are you using a Hell Yes-Code script right?

Try this directly:

`return New Date()`

Or this one:

`return New Date().toLocaleFormat()`

Let me now what you get!

Bye

---

<div class="post-metadata">

**Author:** ![Manu.n](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/manu.n/32/11679_2.png) [@Manu.n](https://community.glideapps.com/u/Manu.n)\
**Post date:** [September 4, 2021, 3:55am UTC](https://community.glideapps.com/t/bug-result-as-date-time-is-not-returned/31345/4 "2021-09-04T03:55:17Z")

</div>

Hello @Maxim_KM  
You may not have the correct version of the driver.js  
Take a test with this one:

```auto

function convert(x) {
  if (x instanceof Date) {
    return x.toISOString();
  } else if (Array.isArray(x)) {
    return x.map(convert);
  } else {
    return x;
  }
}

window.addEventListener("message", async function(event) {
  const { origin, data: { key, params } } = event;
 
  let result;
  let error;
  try {
    result = await window.function(...params);
  } catch (e) {
    result = undefined;
    try {
      error = e.toString();
    } catch (e) {
      error = "Exception can't be stringified.";
    }
  }

  const response = { key };
  if (result !== undefined) {
    result = convert(result);
    response.result = { type: "string", value: result };
  }
  if (error !== undefined) {
    response.error = error;
  }

  event.source.postMessage(response, "*");
});

```

If you make a new Date with this version of the driver, you will have the date in GMT.

you have to return the date in string format, so yes @gvalero with toLocaleDateString () should also work.  
(note that toLocaleFormat is deprecated  
[Deprecated and obsolete features - JavaScript | MDN](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Errors/Deprecated_toLocaleFormat))

But if you want to manipulate dates, I encourage you to take this ‘date-Test’ script as a starting point, you don’t have to worry about regional settings or the time difference for the return date-times. .

> [@Date Hell](https://community.glideapps.com/t/date-hell/31031/6):
>
> I share with you the code I made to test the Glide \<-\> JS conversion. There are 2 two scripts: for a Date column for an Array Split (depends on the 1st script) The idea is to come and go and confirm the conversion. Script 1, Date Column Test YC [https://Date-Test.manun2.repl.co](https://Date-Test.manun2.repl.co) Source [https://replit.com/@ManuN2/Date-Test?v=1](https://replit.com/@ManuN2/Date-Test?v=1) Script 2, Array Test YC [https://Date-Test-Array.manun2.repl.co](https://Date-Test-Array.manun2.repl.co) Source : [https://replit.com/@ManuN2/Date-Test-Array?v=1](https://replit.com/@ManuN2/Date-Test-Array?v=1) Please give me a feedb…

if you have any questions, i’m getting to know the subject a bit!

---

<div class="post-metadata">

**Author:** ![Maxim\_KM](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maxim_km/32/29274_2.png) [@Maxim\_KM](https://community.glideapps.com/u/Maxim_KM)\
**Post date:** [September 4, 2021, 8:58am UTC](https://community.glideapps.com/t/bug-result-as-date-time-is-not-returned/31345/5 "2021-09-04T08:58:02Z")

</div>

Yep, driver.js with convert function solves problem. Hadn’t realized that can debug and fix it’s work 🙂  
@Mark I propose updating example scripts with better driver.js, as many of us use them as starting point for own functions(including dates)

---

<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:** [September 4, 2021, 12:36pm UTC](https://community.glideapps.com/t/bug-result-as-date-time-is-not-returned/31345/6 "2021-09-04T12:36:23Z")

</div>

> [@Manu.n](#):
>
> with toLocaleDateString () should also work.  
> (note that toLocaleFormat is deprecated  
> [Warning: Date.prototype.toLocaleFormat is deprecated - JavaScript | MDN](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Errors/Deprecated_toLocaleFormat))

Thanks for the advice @Manu.n, I haven’t read this warning before!

Feliz día

---

<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:** [September 4, 2021, 3:34pm UTC](https://community.glideapps.com/t/bug-result-as-date-time-is-not-returned/31345/7 "2021-09-04T15:34:49Z")

</div>

Hi again,

Just to document to problem source:

If this statement is omitted or deleted in **Driver.js** , the _New Date()_ sentence will return blank always:  
`return x.toISOString();`

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

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/1/0/1092b077401ab9269502602aee1a0f91f8e66ed8.png)

To get a valid value (date), you must use this method or other equivalent:

`new Date().toLocaleString()`

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

Instead, if you keep `return x.toISOString() ` in your in **Driver.js** , the Date() command will return a value (what Maxim\_KM can’t get):

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

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

That was one of rocks I faced days ago trying to understand how date formats work and return values

Feliz día!

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [September 4, 2021, 11:34pm UTC](https://community.glideapps.com/t/bug-result-as-date-time-is-not-returned/31345/8 "2021-09-04T23:34:12Z")

</div>

Thanks for this detailed post!

---

<div class="post-metadata">

**Author:** ![NoCodeAndy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/nocodeandy/32/62530_2.png) [@NoCodeAndy](https://community.glideapps.com/u/NoCodeAndy)\
**Post date:** [January 17, 2024, 4:50pm UTC](https://community.glideapps.com/t/bug-result-as-date-time-is-not-returned/31345/9 "2024-01-17T16:50:42Z")

</div>


