How to use database query data with data transformations?

have you possible tried making datetimeoffset(7) into something a little less precise like datetimeoffset(2), just a thought

I could try that, but I think the bigger question is how to conditionally evaluate the values in an ASP.NET application. I wonder what the Wappler (@psweb or @Teodor) team would say.

Is there an ASP.NET equivalent to: OutDateTime == null ? TIMESTAMP : OutDateTime.toTimestamp() so the null values can be included in the query?

I assume this is some kind of reservation booking, so you have values for all the InDateTime fields, but the OutDateTime may sometimes be known and other times may not be known, therefore its NULL, however the OutDateTime will always be greater than the InDateTime.

So can we replace null versions of OutDateTime with the current datetime of checking the system?

Something like

{{OutDateTime.default(NOW).dateDiff('days', InDateTime)}}

This way it should replace NULL with the current datetime

That’s the idea, except that it’s a timeclock for tracking employees time. There is an app that employees use to enter their time and I’m trying to build an admin portal to see and manage the records. So, if the OutDateTime is null, that means the employee is clocked in currently and we could use NOW or TIMESTAMP to be the assumed value.

I tried the .default(NOW) method, but got an error:

DateDiff can not do it all in one like that the first parameter can only take 1 variable, so hours or minutes or seconds. In your case better use this

{{(OutDateTime.default(TIMESTAMP) - InDateTime.toTimestamp()).formatDate('HH:mm:ss')}}

Tried that but get the same error. Seems the problem is with the .default() method, as it’s trying to convert OutDateTime to boolean.

The .default() formatter is meant to work only when “no value exists” so specifically for NULL returned values. On records where OutDateTime has a value of a proper datetime it will ignore the default parameter and use the real value. Well at least that is how it should work.

In the .default() you can put anything really, like dynamic or static data, so

.default(NOW)
.default(NOW_UTC)
.default(TIMESTAMP)
.default('My Dog bit me')
.default(InDateTime)
.default(53)

Your alternative is similar and that is adding a condition step inside the repeat, the condition expression will be OutDateTime from the repeat bindings

Whatever you add inside the Then part fires when the condition is True, ie OutDateTime has a value and everything in the Else step fires when the condition is False ie OutDateTime is NULL

Do you have a live testing server I can see this on possibly.


Your alternative worked!! With one modification; I changed the condition to {{OutDateTime == ‘’}} and that seemed to do the trick.

I thought maybe that would work in the expression, but I tried it and it failed. Seems you can’t use a condition in an expression, for an ASP.NET project…

Thanks so much for your help!

1 Like

Awesome, happy we got something to work.

One more question, if you change the query to a Paged Records query, how do you include the setValue column in the data? I’m getting a separate property from the repeat.


Basically, I’m getting the actual data twice. Once in ‘data’ and again in ‘repeat’. What I need is ‘data’ to be replace with ‘repeat’.

If you change to a paged query, then your repeat expression has to change from {{query}} to {{query.data}} and then all your bindings should pretty much remain the same.

Yes, that’s what I did, and everything continues to work correctly, except I have another whole set of data in a separate property. With the previous query (Muiltiple Records), I turned off the output of the query and included all the fields in the repeat output and everything was there. But I can’t do that here, because I loose the paging properties. Guess I have to reference the repeat separately on the client?

You do not have to output the data in order to reference nor interact with it, you only have to output it to display it really.

So turn off the output of your paged query, turn on the output of your repeat, and you do not have list all the output fields, if you leave it blank, they will all be output.

If your database table has 10 columns, and your query only uses 3 of the 10 and you repeat the query then only 3 columns will be output, if you wanted less than the 3 you could add the 1 or 2 you want in the Output fields.

Once your page shows up, you can alter what records are displayed with URL parameters, so just add to the end of your URL ?offset=25 and it will show the next batch of records

Is that what you are getting? It’s not what I’m getting. I only get the repeat field that it adds and nothing else.


You can see it’s only the dateDiff field.

Here is how I have it configured:

Yes thats the same as what i get, now append to your URL bar ?offset=25 and the displayed data in the repeat will change.

What are you trying to output from that? Sorry I am confused what is not working.

I’m not getting the rest of my columns in the output. Only the dateDiff values, nothing else.

Ahh I see, sorry, I think something is different to how it used to be, just tested this myself, and you right, you have to set the Output fields for all that you want, as nothing does not output everything as I thought, but outputs nothing.

I am almost certain that never used to work that way, but not sure, I could be wrong.

That’s what I thought too. Almost sure I saw that someplace in the documents, but I’d have to go looking again. Seems odd that you’d have to select all the columns over again.

1 Like