Gnuplot - start date and time + incremented minutes - date

I have a question about Gnuplot - my measurement device records the start date and time (ex. 15.09.2020 15:09:00 format can be changed), every measurement is done after every 60 minutes. I do not know the ending time. How should I do the x-axis, so that axis tics are "day.month" ?

Keep in mind, in gnuplot time and date is handled as seconds from January, 1st 1970 00:00:00.
In gnuplot console check help strptime, help format. Try the following:
Code:
### convert relative time into absolute time
reset session
$Data <<EOD
minutes;temperature
0;12.8829
60;4.5346
120;4.5417
180;4.5454
240;4.5394
1440;2.22
2880;1.11
10000;0.00
EOD
set datafile separator ";"
Startdate = strptime("%d.%m.%Y %H:%M:%S","15.09.2020 15:09:00")
myTime(col) = Startdate + column(col)*60
set format x "%d.%m." timedate
plot $Data u (myTime(1)):2 w lp pt 7
### end of code
Result:

I know, that temperature logger started:
15.09.2020 15:09:00
The datafile.csv contains:
minutes;temperature
0;12.8829
60;4.5346
120;4.5417
180;4.5454
240;4.5394

Related

How to convert formatted date to unix epoch in Libreoffice calc

I have column with cell format date or time (DD.MM.YYYY HH:MM:SS) and values like
03.12.2013 14:01:49
04.12.2013 10:19:27
04.12.2013 12:44:56
04.12.2013 14:20:12
04.12.2013 18:30:21
I need those values converted to unix epoch (seconds since 1970). Somehow it feels like the values are not recognized as dates, but rather as strings. I tried different formats, had little luck with dates without time.
Operations performed on date data should be automatic provided that the cells are formatted as as a user defined DD.MM.YYYY HH:MM:SS in the 'Format' > 'Cells' > 'Numbers' tab.
If you're using the standard settings, LibreOffice Calc uses 12/30/1899 as it's default date. So the first step is getting the number of days between 12/30/1899 and 1/1/1970:
=(DATE(1970,1,1) - DATE(1899,12,30)) = 25569
Number of seconds in a day:
=(60 * 60 * 24) = 86400
If, for example, in cell A2 you have the date 03.12.2013 14:01:49. I subtract the difference between Calc's default date and the Unix Epoch we just calculated, and multiply it by the number of seconds in a day:
=(A2 - 25569) * 86400
The result is a value of 1363096909 which is the Epoch time in seconds. If you need it in milliseconds, multiply the equation by 1000.
If it's something you use a lot, you can create a custom function that does this. Go to Tools > Macros > Edit Macros, and type out the following into whichever module comes up:
REM ***** BASIC *****
Function EPOCH(date_cell)
EPOCH = (date_cell - 25569)*86400
End Function
Close the macro IDE, and now you can use your EPOCH() like any other function!
This formula worked for me, where the others above did not:
= DATE( 1970, 1, 1 ) + ( A1 / 86400 )

add incremnting seconds to time in HH:mm:ssPM format

How to add a vector of seconds to time HH:mm:ssPM in MATAB?
I usually have this nice way in Excel to convert normal number format to hour and minutes and sec. format using simple cell custom formatting, but when I put down code below in MATLAB, instead of incrementing in seconds, it adds in days!
time = 1+0:50000+0; % sec
% To show date as plot label it should be converted from numbers to letters
hr_matlab = time' + datenum('4:10:44 PM');
hr= datestr(hr_matlab, 'HH:MM:ssPM');
figure(222)
plot(hr,S,'-b','LineWidth',2)
I am using MATLAB2014a and don't have access to function datetime.
datenum converts the date to a number that represents days as whole numbers. For that reason, when you add the vector [1,2,3,...], you acturally add days to your fixed time ('4:10:44 PM').
if you want to add it as seconds, you need to divide time in the amount of seconds per day:
hr_matlab = (time')/86400 + datenum('4:10:44 PM');
One simple option is to add two date numbers:
hr_matlab = datenum('4:10:44 PM') + datenum(0, 0, 0, 0, 0, time.');

Date Time Conversion: Number to Date Time

I have date & time in intervals of one hour(3600 seconds) in number format, e.g 0,3600, 7200, 10800, 14400, 18000 etc.
I have starting date and time , e.g 0 corresponds to 2005/06/01 01:00 in 'yyyy/mm/dd HH:MM' format.
I am writing this data to Excel file, so I am looking for way where I can convert time given in Hour (in seconds) to Date Time (2005/06/01 01:00, 2005/06/01 02:00 etc) before writing to excel file.
I have explored 'datenum' and 'datestr' functions but they are not useful since I can not give them customised start time i.e (0 corresponds to 2005/06/01 01:00).
May be if some one can help me to point me in right direction.
tempMatrix = [NrID time_inSec ff X Y];
tempMatrix_dataCell=num2cell(tempMatrix);
col_header={'NrID','Time','ff','X','Y'};
data_for_xls_file=[col_header; tempMatrix_dataCell];
xlswrite('My_file.xls',data_for_xls_file);
time_inSec is column with values 0, 3600, 7200, 10800 etc which need to be converted.
When I use datenum it returns 7.3246e+05 so when I add 3600 to get 2005/06/01 02:00 and pass it to datestr it returns 2015/04/10 01:00.
temp_time = datenum('2005/06/01 01:00','yyyy/mm/dd HH:MM')
This works with a given start time:
startTime = datenum('2005/06/01 01:00', 'yyyy/mm/dd HH:MM'); % Define start time.
currentTime = datenum('2005/06/01 02:00', 'yyyy/mm/dd HH:MM'); % Current time.
timePassedHours = (currentTime - startTime) * 24; % Time that has passed in hours.
display(timePassedHours); % Print the output.

VB Scripting - comparing time values, one coming from a text file?

I'm attempting to pull some information out of text file that is updated after I query a piece of equipment. The text file contains lines such as shown here (abbreviated):
05-Nov-13 11:11:54.3496 ( -1 7020 10244) scpeng.exe:Automation Server...
05-Nov-13 14:10:54.3496 ( -1 7020 10244) scpeng.exe:Automation Server...
05-Nov-13 14:10:54.3496 ( -1 7020 10244) scpeng.exe:Automation Server...
05-Nov-13 14:10:56.3496 ( -1 7020 10244) scpeng.exe:CServer.cpp,....
The text file can contain up to several weeks of information. I have a subroutine that will run a few seconds after I query the equipment which should allow for the reply and the applicable line to be present in the text file. In the routine, I am trying to scroll through the lines examining the date to arrive at the date of the subroutine call followed by the time (or a time ~10 seconds prior the the current time) to arrive at the lines pertinent to where the information could be found.
do
msg = msgstream.ReadLine
logdate = mide(msg,1,9)
logday = Cdate(logdate)
loop while logday < date
do
msg = msgstream.Readline
logtime = mid(msg,12,8)
'logtime = CDate(logtime) This mod is not working
loop while logtime < time
The date loop appears to work however the time is giving me problems. It does not error out but I can't get it to run beyond one line of text. Can anyone suggest a fix or better option? I have read that the built-in Date function can include the time but I do not believe this version I'm using does. Also, the text file contains times in a 24 hour format where I believe the time function returns values in a 12 hr format ie "12:43:27 PM ST".
You're making this way too complicated. Simply parse the whole date string into a datetime value:
refdate = Now
Do
msg = msgstream.ReadLine
logdate = CDate(Mid(msg, 1, 19))
Loop While logdate < refdate
You can extract date and time portions from the value later, e.g. like this:
WScript.Echo DateValue(logdate)
WScript.Echo TimeValue(logdate)
Also, Time returns the current (unformatted) system time. Whether it's displayed in 12 hour or 24 hour format depends on your system's region settings. However, you can always get the hour (0-23) by using the Hour function.
Parse each line with a regex to get the correct date and time part. I prefer a regexp above string manipulation functions because you can separate format and code.
Reassemble the date from the two parts and see if the date is smaller than yesterday at this time.
Option Explicit
dim strTest, re, matches, myDatePart, myTimePart, logDate
' teststring
strTest = "08-Nov-13 14:10:56.3496 ( -1 7020 10244) scpeng.exe:CServer.cpp,...."
Set re = new regexp
' This pattern extracts two part, the date as (dd-www-dd) and the time as (hh:mm:ss)
re.pattern = "(\d{2}-\w{3}-\d{2}) +(\d{2}:\d{2}:\d{2})"
Set matches = re.Execute(strTest)
' Get the first and second submatch to define the date and time
myDatePart = matches(0).submatches(0)
myTimePart = matches(0).submatches(1)
' datevalue and timevalue automatically tranforms to Date type
logDate = datevalue(myDatePart) + timevalue(myTimePart)
' See if the date is smaller than yesterday exactly this time
msgbox (logDate < (DateAdd("d", -1, now))) ' Returns True, because 08 Nov is earlier than yesterday.

UTC Time to String Conversion

I am looking for helping doing time conversions from UTC time to string using MATLAB.
I am trying to extract time from a data file collected at the end of October 2010.
The data file says it is reporting in UTC time and the field is an integer string value in milliseconds that is around 3.02e11. I would like to convert this to a string but am have some trouble.
I figured out that the units are most definitely in milliseconds so I convert this to fractions of days to be compatible with datenum format.
If the data was collected at the end of October (say, October 31, 2010) then I can guess what kind of number I might get. I thought that January 1, 2001 would be a good epoch and calculated what sort of number (in days) I might get:
suspectedDate = datenum('October 31, 2010')
suspectedEpoch = datenum('January 1, 2001')
suspectedTimeInDays = suspectedDate - suspectedEpoch
Which comes out as 3590.
However, my actual time, in days, comes out with the following code
actualTime = 3.02e11
actualTimeInDays = 3.02e11/1000/24/3600
as 3495.4.
This is troubling as the difference is only 94.6 -- not a full year. This would mean either the documentation for the file is wrong or the epoch is close to April 1-5, 2001:
calculatedEpoch = suspectedDate - actualTimeInDays
calculatedEpochStr = datestr(calculatedEpoch)
Alternately, if the epoch is January 1, 2001 then the actual date in the file is from the end of July.
ifEpochIsJanuaryDate = suspectedEpoch + actualTimeInDays
ifEpochIsJanuaryDateStr = datestr(ifEpochIsJanuaryDate)
Is this a known UTC format and can anyone give suggestions on how to get an October date from 3.02e11 magnitude number?
Unix time today is about 13e11, and is measured in ms since 1970.
If your time is ~3e11, then it's probably since year 2000.
>> time_unix = 1339116554872; % example time
>> time_reference = datenum('1970', 'yyyy');
>> time_matlab = time_reference + time_unix / 8.64e7;
>> time_matlab_string = datestr(time_matlab, 'yyyymmdd HH:MM:SS.FFF')
time_matlab_string =
20120608 00:49:14.872
Notes:
1) change 1970 into 2000 if your time is since 2000;
2) See the definition of matlab's time.
3) 8.64e7 is number of milliseconds in a day.
4) Matlab does not apply any time-zone shifts, so the result is the same UTC time.
5) Example for backward transformation:
>> matlab_time = now;
>> unix_time = round(8.64e7 * (matlab_time - datenum('1970', 'yyyy')))
unix_time =
1339118367664
You can't just make up your own epoch. Also datenum returns things in days. So the closeness you got with doing your math was just a coincidence.
Turns out that
>> datenum('Jan-1-0000')
ans =
1
and
>> datenum('Jan-1-0001')
ans =
367
So Matlab should be returning things in days since Jan. 1, 0000. (Not a typo)
However, I'd look carefully at this 3.02e11 number and find out exactly what it means. I'm pretty sure it's not standard Unix UTC, which should be seconds since January 1, 1970. It's way too big. It's close to GMT: Mon, 1 Jan 11540 08:53:20 UTC.