[Solved] Determine elapsed time between two button clicks

Creating tables and queries
Post Reply
Korsakoffy
Posts: 4
Joined: Wed Jan 26, 2022 8:22 pm

[Solved] Determine elapsed time between two button clicks

Post by Korsakoffy »

Hello!

I hope I'll be able to make me understood here, but I am completely new to OpenOffice and Base.

I'm trying to create a system that would allow me to click a button to insert a timestamp to a table twice and for it to tell me what time has passed during those two clicks. Is there a simple way someone could try and explain what I am supposed to do?

I've been trying to find tutorials all over the net the entire day, but all of the ones I've been able to find are simply how to set up tables.

Thank you in advance!
 Edit: Changed subject, was Attendence 
-- MrProgrammer, forum moderator 
OpenOffice 4.0 Windows 11
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Attendence

Post by Villeroy »

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Korsakoffy
Posts: 4
Joined: Wed Jan 26, 2022 8:22 pm

Re: Attendence

Post by Korsakoffy »

That is a great example, and I've gone through it multiple times. And there's multiple things I could learn from this, so thank you a lot!

Timestamping and everything is great, but is there any way to compare two timestamps to get the total time a "key" has been borrowed?

What I'm trying to do is basicly a clock in and out system for my small business, and in the long run the goal is to have an "overtime bank". Where if someone works over 40 hours one week, every extra hour gets stored in a table, and if they work less than 40 hours every missing hour gets removed from said table.

Is this something that is even realistic with Base, or should I look somewhere else?
OpenOffice 4.0 Windows 11
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Attendence

Post by Villeroy »

The embedded HSQLDB 1.8 is documented here: http://www.hsqldb.org/doc/1.8/guide/ch09.html
See function DATEDIFF for the date/time difference.
The Base GUI does not provide the time stamp as default value. You have to do this on the SQL command line:
menu:Tools>SQL...

Code: Select all

ALTER TABLE "table name" ALTER COLUMN "column name" SET DEFAULT CURRENT_TIMESTAMP
menu:Tools>Refresh Tables (tell Base that the database has been modified)
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Korsakoffy
Posts: 4
Joined: Wed Jan 26, 2022 8:22 pm

Re: Attendence

Post by Korsakoffy »

I've been looking through your guide, and I have found multiple threads that has the functions I desire.

But being new to all of this I'm having a difficult time understanding how I am supposed to tie them all together.

viewtopic.php?f=13&t=70064
This thread showed me a system that works great, but it's missing the duration, it even has the ability to switch eomployee with a drop down box.

viewtopic.php?f=13&t=71414
This thread has some other useful information, especially the .dbo F3K posted.

I would likle to built it from the ground up, but would need some help understanding what way to go. Could someone explain this to me like I'm 3?
OpenOffice 4.0 Windows 11
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Attendence

Post by Villeroy »

You are dealing with 2 different softwares. You control some database program (HSQL 1.8 in this case) by means of an office suite.
Creating tables, relations and indices Base issues CREATE, ALTER and DROP commands to the database ("data definition language").
While editing table data in grid views and forms, Base issues INSERT, UPDATE, DELETE commands to the database ("data manipulation language").
Base can do most of the DDL and DML for you. I mentioned auto timestamps as one exception where you have to use the SQL command line.
-------------------------------------------------------------
SELECT statements read data from the database, calculate stuff and return row sets back to the office suite where they are displayed in grids, forms, reports, Writer or Calc documents. Queries are somewhat similar to spreadsheet formulas. They reference existing data, process them and return a single value (spreadsheet formula) or a row set (SELECT). SELECT statements are stored in queries mostly. In my example files you may find some SELECT statements in a form's properties dialog.
The basics of SQL are easy to learn (easier than spreadsheet formulas), however things can get highly sophisticated because SQL is more powerful than spreadsheet langauge.
When you double-click a table, Base queries SELECT * FROM "Table" and loads the first screen full of data into a grid view.
The query

Code: Select all

SELECT *, DATEDIFF('day', "date_column", CURRENT_DATE) AS "Days" 
FROM "Table" 
returns all the rows and columns from "Table" plus a calculated column labeled as "Days" showing the days between "date_column" and the current date.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Korsakoffy
Posts: 4
Joined: Wed Jan 26, 2022 8:22 pm

Re: Attendence

Post by Korsakoffy »

Villeroy wrote:You are dealing with 2 different softwares. You control some database program (HSQL 1.8 in this case) by means of an office suite.
Creating tables, relations and indices Base issues CREATE, ALTER and DROP commands to the database ("data definition language").
While editing table data in grid views and forms, Base issues INSERT, UPDATE, DELETE commands to the database ("data manipulation language").
Base can do most of the DDL and DML for you. I mentioned auto timestamps as one exception where you have to use the SQL command line.
-------------------------------------------------------------
SELECT statements read data from the database, calculate stuff and return row sets back to the office suite where they are displayed in grids, forms, reports, Writer or Calc documents. Queries are somewhat similar to spreadsheet formulas. They reference existing data, process them and return a single value (spreadsheet formula) or a row set (SELECT). SELECT statements are stored in queries mostly. In my example files you may find some SELECT statements in a form's properties dialog.
The basics of SQL are easy to learn (easier than spreadsheet formulas), however things can get highly sophisticated because SQL is more powerful than spreadsheet langauge.
When you double-click a table, Base queries SELECT * FROM "Table" and loads the first screen full of data into a grid view.
The query

Code: Select all

SELECT *, DATEDIFF('day', "date_column", CURRENT_DATE) AS "Days" 
FROM "Table" 
returns all the rows and columns from "Table" plus a calculated column labeled as "Days" showing the days between "date_column" and the current date.
Could I change it to?

Code: Select all

SELECT *, DATEDIFF('day', "TimestampIn", TimestampOut) AS "ClockedTime" 
FROM "WhateverIcallmyTStable" 
Am I understanding the code like intended?
I feel like I understand every part of the code, except for the first "day" after DATEDIFF. What is the purpose of that one?
OpenOffice 4.0 Windows 11
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Attendence

Post by Villeroy »

HSQL documentation wrote:DATEDIFF(string, datetime1, datetime2)[2]

returns the count of units of time elapsed from datetime1 to datetime2. The string indicates the unit of time and can have the following values 'ms'='millisecond', 'ss'='second','mi'='minute','hh'='hour', 'dd'='day', 'mm'='month', 'yy' = 'year'. Both the long and short form of the strings can be used.
The same function can calculate any unit of time based on the literal string in the first agument.
Literal strings in single quotes.
Names of tables and columns in double quotes.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply