Date Time picker only transmitting the date when sending a datetime to sql


The datetime is not being sent to SQL, only the date. Seems to have just started happening, as I was not having this issue prior to today.

Hi @mkatzaroff,

It’s a bit difficult to guess what’s wrong as you only mention the issue.
If you could provide some more info, we could help better. Like, how do you pass the value to the query, just passing the Date object or something else? Or what kind of database are you using? Etc.

Hi @Max ,

The data is from a datetime field in the UI (happens on both the form and stand alone Date & Time components). The data is directly passed to a SQL step in an action. The problem is that in the payload, it is stripping the time value from the variable, so instead of ‘2025-03-03 13:30’ it is only sending ‘2025-03-03’.

–side note, in the screen shot, I had previously ran the action so in the payload section it has the previous value, hence the difference in the dates. If I had ran that action as it was, it would have only sent ‘2025-01-19’ instead of the date with the time

@Max
I think I may have figured it out. I was just able to get it to work by adding “.toISOString()” to the end of the data binding

@mkatzaroff

Yes, transforming the value to a format SQL can understand should do the trick. But remember, toISOString() yields a date in the format YYYY-MM-DDTHH:mm:ss.sssZ. SQL doesn’t understand the Z at the end, so just toISOString().slice(0,-1) leave that part away.


If your app works with dates a lot, I highly recommend using a library that handles these things, as it can get really complicated with locales, time zones, leap years, etc. It’s better not to reinvent the wheel, as those libraries handle all those cases very well and are generally light-weight.

If you would rather not use a library, nowadays, you probably don’t need a library anymore. This article shows how the modern ECMAScript, using some Date functions and the Intl Internationalization API, can do a lot with dates natively in JavaScript.

Regarding libraries, the standard used to be moment.js, but that project has come to a halt and is now a legacy project; it is strongly recommended to use a different library.

Read more on the project status of moment.js

The best libraries to use today, which are also mentioned on the “Project status” page of moment.js, are

All 3 are suitable alternatives, and it truly depends on your specific needs and preferences which one you should pick. They are all much smaller (Day.js comes down to 6.9kB!!!) compared to Moment and provide the same and even more functionalities.

This github project showcases the main difference between the three libraries.

I have used moment.js for a few items, but for the most part I have been using getutcdate() in a SQL query if I need to fill the date for an insert statement (typically date inserts are for a status log, which needs the current time anyway).
SQL also handles the dates provided by toISOString() just fine with the Z at the end (so no need to trim it), but .toISOString() does not handle nulls, so I had to come up with a workaround for when the value is null to not parse .toISOString() at all:

{{date_field.value === null ? null : date_field.value.toISOString()}}

Oh it does? I mean, personally when I try to insert with the Z it yields specifically a date format error:
Error Code: 1292. Incorrect datetime value: '2025-03-10T07:56:01.273Z' for column 'someDate' at row 1

But that might be difference in version or whatever, as long as it works for you.
And as for the null handling, it depends on what role the date plays. If it’s rather important, I’d stop the whole action beforehand, but I think you’ll make it work just fine :+1:

You could write the snippet there at the end a bit short using the optional chaining operator:
{{date_field.value?.toISOString()}}