Help with Simple Calculated Field

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
mgoetze
Posts: 23
Joined: 2014-12-02 06:59

Help with Simple Calculated Field

Post by mgoetze » 2022-02-08 19:11

Hi All,
I am a SQL newbie so I was hoping to get some help with setting up a calculated field. My requirement is very basic, I have two date fields and one calculated field. I would like the calculated field to calculate the number of days between the two date fields. For example:

Field 1: 2022-01-01
Field 2: 2022-02-05
Field 3: 35 Days (this is the calculated field)

what would be the SQL query for the above?

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1709
Joined: 2018-04-01 10:12

Re: Help with Simple Calculated Field

Post by pbottcher » 2022-02-08 21:28

hi, you can use the search function for searching the forum. A lot of tips can be found here. Have a look at viewtopic.php?t=3789
this should give you a good starting point
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

mgoetze
Posts: 23
Joined: 2014-12-02 06:59

Re: Help with Simple Calculated Field

Post by mgoetze » 2022-02-08 22:32

I did search and I saw that link, but unfortunately my knowledge of SQL is non-existent so I have no idea how to interpret what the other users were doing with SQL. To be honest I am hoping that someone can tell me the correct SQL statement so I can complete my project, I wish I had more time to learn SQL but I dont at the moment. Any specific help would be greatly appreciated.

User avatar
zibrahim
Veteran Member
Posts: 170
Joined: 2020-01-28 18:30
Location: Malaysia

Re: Help with Simple Calculated Field

Post by zibrahim » 2022-02-09 00:42

Hello there,
A simple SQL statement should be like this.

Code: Select all

SELECT DATEDIFF(field_2, field_1) FROM TABLENAME 
WHERE id='%ID%'
Replace field_2, field_1, TABLENAME & id according to your table and fields definition accordingly.

Stay safe.
Zala.
Appgini 25.12, MacOS 15.5 Windows 11 on Parallels.

mgoetze
Posts: 23
Joined: 2014-12-02 06:59

Re: Help with Simple Calculated Field

Post by mgoetze » 2022-02-10 17:57

This worked perfectly. Thank you.

hubert
Veteran Member
Posts: 50
Joined: 2018-12-06 22:32

Re: Help with Simple Calculated Field

Post by hubert » 2022-02-18 17:41

Hi

Have the same request, result is ok but ...
Database is about WW1.
Works fine if date is after 1970-01-01
Doesn't work with earlier date

SQL in calculated field is this :
SELECT DATEDIFF(date,'1914-08-02') FROM mouvements WHERE id='%ID%'

Seems it' a Unix timestamp trouble and if date is set before 1970, date fiels is set to null and of course no result ...

Any key ?

Post Reply