MySQL database help (storing time and date)
Discussion
I have a load of comma delimited text files that have two columns of data: (time and data)
They look like this:
00:02:05,383.94
Each file is created on a specific day, using the date for the filename e.g. 29-08-2021.log
I want to store this data in a MySQL database - however I can't think of the best approach.
Obviously, I could create a database with two columns as per above, but then I lose the date stamp - so then I could create a third column e.g. date,time,data
This is on a Linux system - so what would be the best way to store the date / time? Should I use epoch format? Then of course I would only need two columns is that right? (epoch date, data)
Thanks in advance.
They look like this:
00:02:05,383.94
Each file is created on a specific day, using the date for the filename e.g. 29-08-2021.log
I want to store this data in a MySQL database - however I can't think of the best approach.
Obviously, I could create a database with two columns as per above, but then I lose the date stamp - so then I could create a third column e.g. date,time,data
This is on a Linux system - so what would be the best way to store the date / time? Should I use epoch format? Then of course I would only need two columns is that right? (epoch date, data)
Thanks in advance.
I'm finally getting around to looking at this again.
I have created my database which has two columns, date_time and power.
I am using 'timestamp' for the date_time column - and storing the date like this: 2021-11-02 10:10:00
Is this correct?
EDIT corrected the data in my power column - it should have indeed been a decimal point and not a comma.
I have created my database which has two columns, date_time and power.
I am using 'timestamp' for the date_time column - and storing the date like this: 2021-11-02 10:10:00
Is this correct?
select * from Test;
+----+---------------------+-------+
| id | date_time | power |
+----+---------------------+-------+
| 1 | 2021-11-02 10:10:00 | 35.95 |
+----+---------------------+-------+
1 row in set (0.001 sec)
EDIT corrected the data in my power column - it should have indeed been a decimal point and not a comma.
Edited by TonyRPH on Tuesday 2nd November 12:18
TonyRPH said:
select * from Test;
+----+---------------------+-------+
| id | date_time | power |
+----+---------------------+-------+
| 1 | 2021-11-02 10:10:00 | 35,95 |
+----+---------------------+-------+
1 row in set (0.001 sec)
If you want to use it as a number (analysis, charting, etc) then store it as a number
Edited by nyt on Tuesday 2nd November 11:47
bigandclever said:
TonyRPH said:
Is this correct?
>consulting_hat_onWhat do you want to do with it once you've stored it?
>consulting_hat_off
I will also be performing some mathematics on it to derive daily / monthly / annual figures. (this is for my energy monitor at home)
@the internet the data will be extracted with PHP which has my timezone set as appropriate. The data will only be added and read / used by me, so I don't need to allow for any other date formats.
nyt said:
TonyRPH said:
select * from Test;
+----+---------------------+-------+
| id | date_time | power |
+----+---------------------+-------+
| 1 | 2021-11-02 10:10:00 | 35,95 |
+----+---------------------+-------+
1 row in set (0.001 sec)
If you want to use it as a number (analysis, charting, etc) then store it as a number
Edited by nyt on Tuesday 2nd November 11:47
The power column is currently defined as TEXT but I see I have DECIMAL, FLOAT, DOUBLE and REAL options - I guess DECIMAL would be best here?
Thanks everyone.
TonyRPH said:
Well spotted, that's a mistake on my part, the power data is using a decimal point.
The power column is currently defined as TEXT but I see I have DECIMAL, FLOAT, DOUBLE and REAL options - I guess DECIMAL would be best here?
Thanks everyone.
I would use Float. Decimal would probably work for your purposes but I'd expect to see float or double used in most cases.The power column is currently defined as TEXT but I see I have DECIMAL, FLOAT, DOUBLE and REAL options - I guess DECIMAL would be best here?
Thanks everyone.
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff



