42
Views
5
Comments
Solved
Get weekday name from date in database
Question
Application Type
Reactive
Service Studio Version
11.55.3 (Build 63884)

Hi,

I'm new with Outsystems and building a personal application with it now. That application is an portfolio where I can log my dispatches as volunteer firefighter. I also created some graps for it, and now I'm expanding it with some more details.

One of the details is a graph (or table) where I can see a counter for every weekday. So for a given period (using filters for that) I want to see how many dispatches there where for every day.

Of course I'm saving a date on every record, but I have troubles converting that into a weekdayname.
I'm now trying to get the weekday name as new attribute with a formula. But the `FormatDateTime` function is not working in the database. 

`FormatDateTime(Dispatch.Date, "dddd")`

'FormatDateTime' function cannot be executed in the database, so it can't receive any attributes from the aggregate as parameter.`

I read some other questions like these:

https://www.outsystems.com/forums/discussion/81179/dayofweek-to-text/#
(this uses the same function so the same error occurs)

https://www.outsystems.com/forums/discussion/40947/sort-by-month-in-aggregate-on-a-date-attribute/#
(this works only for grouping on year or month)

Of course I do something wrong,but I don't see what right now.

Can you help me?

2020-07-21 19-28-50
Rajat Agrawal
Champion
Solution

Hi @Niek van Oost 

You get week day name like 

apply below formula in calculate attribute

If(DayOfWeek(new.Date)= 0,"Sunday",If(DayOfWeek(new.Date)= 1,"Monday",If(DayOfWeek(new.Date)= 2,"Tuesday",If(DayOfWeek(new.Date)= 3,"Wednesday",If(DayOfWeek(new.Date)= 4,"Thursday",If(DayOfWeek(new.Date)= 5,"Friday",If(DayOfWeek(new.Date)= 6,"Saturday","")))))))

UserImage.jpg
Niek van Oost

Thanks! I was currently building something like that indeed. I noticed that the DayOfWeek function worked well, so I had a graph with 0, 1 as daynames indeed.

2023-02-20 05-20-57
Nam Nguyen

Hi, 
You can mask data in the OnAfterFetch Event. 

Create a local variable and bind your table with it.
In the OnAfterFetch, implement your logic for masking your data with FormatDateTime

Nam

UserImage.jpg
Md Mansur

Hi @Niek van Oost 

Step1: When you Can Call Aggregate on you screen than first add one new Attribute Like this:

Step 2: in new Attribute you show this Things :

Step 3: add Formula you can simple copy and Paste below Code and Replace Date to you own Aggregate Date:

If(DayOfWeek(User.Creation_Date)= 1,"Monday",If(DayOfWeek(User.Creation_Date)= 2,"Tuesday",If(DayOfWeek(User.Creation_Date)= 3,"Wednesday",If(DayOfWeek(User.Creation_Date)= 4,"Thursday",If(DayOfWeek(User.Creation_Date)= 5,"Friday",If(DayOfWeek(User.Creation_Date)= 6,"Saturday",""))))))

Thanks

Md Mansur


2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Niek,

Is there a specific reason you want to have the weekday name as output of the Aggregate? I would assume that if you want to display it on screen, you could use the FormatDateTime on the screen. And if you want to display it in a chart, you can use FormatDateTime in the mapping of the Aggregate output to the chart.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.