Google Sheet - convert Hours & minute to seconds - regex

Need to convert Hours & minutes to seconds.
Ex : 5h 30m -> 19800
3h 15m -> 11700
Tried to use Formatting options & the SECOND() function. But it's not working.

if you have 5:30 you can do this:
=TEXT(A7, "[ss]")*1
if you have no idea use:
=INDEX(IFERROR(1/(1/TEXT(REGEXREPLACE(A7:A10&"",
"(\d+)h ?(\d+)m", "$1:$2")*1, "[ss]"))))

Try:
Formula in B1:
=INDEX(IF(A1:A<>"",--REGEXREPLACE(A1:A,"(\d+)h +(\d+)m","$1:$2"),""))
Custom numberformat in B:B is [ss].

Something like this should also work:
=IFERROR(SUMPRODUCT(SPLIT(S4,"hm"),{3600,60}),SPLIT(S4,"h")*3600)

Related

Getting value between '-' in google sheets

Im trying to get the number between '-' and '-' in google sheets but after trying many things I still havent been able to find the solution.
Data record 1
England Premier League
West Ham vs Crystal Palace
2.090 - 3.47 - 3.770
Expected value = 3.47
Data record 2
England League Two
Carlisle vs Scunthorpe
2.830 - 3.15 - 2.820
Expected value = 3.15
Hopefully someone can help me out
Try either of the following
option 1.
=INDEX(IFERROR(REGEXEXTRACT(AE1:AE4," \d+\.\d+ ")*1))
option 2.
=INDEX(IFERROR(REGEXEXTRACT(AE1:AE4,".* - (\d+\.\d+) ")))
(Do adjust the formula according to your ranges and locale)
use:
=INDEX(IFNA(REGEXEXTRACT(A1:A, "- (\d+(?:.\d+)?) -")*1))

SAS - Comparison of Hours

I'm new to SAS and can't seem to compare hours. Let me explain :
I have a Date/Time (format : ddmmmaa:hh:mm:ss) variable that I reformatted (in format TOD8 : hh:mm:ss) to only have the time.
With this specific time, I want to put it into a time slot. So if the time is between such and such time, I give him a time slot.
The problem that arises for me is that I cannot compare the time. Here is my code:
data test;
set WORK.TABLE;
if 'hour'n > '09:00:00't and 'hour'n < '09:59:59't then 'time slot'n=0910;
else if 'hour'n > '10:00:00't then 'time slot'n=1011;
else 'time slot'n=-1;
run;
This gives me the result :
Hour | time slot
------------------------
08:06:00 | 1011
09:30:00 | 1011
11:00:00 | 1011
I think it comes from the type but I can't find any documentation that allows me to solve this problem.
If you have an idea or something that could help me understand this result it will help me a lot. Thanks in advance
The problem is that you applied a format considering it changed the stored value. That's a wrong statement: a format just applies a "display" pattern, no more.
And this is why you can change the format to what you want without losing any information :)
To extract a time from a datetime, use the timepart function.
Then you'll be able to compare this value against other times:
data test;
set work.table;
attrib extracted_hours format=tod5.;
extracted_hours = timepart(your_datetime);
if '09:00:00't <= extracted_hours < '10:00:00't then 'time slot'n = 0910;
else if '10:00:00't <= extracted_hours < '11:00:0't then 'time slot'n=1011;
else 'time slot'n=-1;
run;

AmCharts4: Datagrouping, Tooltiptext and changing ranges

From a server, I get an entry for every hour in the range I request. If I request a range of 1 Year, I get something like 8000 Datapoints.
When rendering the graph, I want to group my data to hours(which is the raw data without grouping), days and months. However, the chart looks like this:
The tooltip does only display on the very first column, all other columns are above 1.5, but my ValueAxis does not scale automatically. I already checked if I set fixed min and max for the valueAxis, this is not the case.
Interestingly, if i use the scrollbar to zoom in until grouping kicks in, everything seems to work:
After zooming out again, it also works, but i cannot see the tooltip on the "June-Column":
And finally, if I trigger "invalidateData" the graph goes back to the state it was before.
My grouping looks as follows:
series = entry.chart.series.push(new am4charts.ColumnSeries());
dateAxis.groupData = true;
dateAxis.groupCount = 40;
dateAxis.groupIntervals.setAll([
{ timeUnit: "hour", count: 1 },
{ timeUnit: "day", count: 1 },
{ timeUnit: "month", count: 1 },
{ timeUnit: "year", count: 1 },
{ timeUnit: "year", count: 10 }
]);
series.groupFields.valueY = "sum";
I am also not very sure what I should set those values to. I want to see:
months when there is a period of 3 months or more
days when there is a period of 3 days until 3 months
hours when there is a period below 3 days
It is very difficult to do a fiddle for this, as there already is so much code and its hard to extract only the essential parts.
Maybe I am missing something obvious, please help!
Edit:
I forgot another question which is part of datagrouping:
How can I make the tooltip to show the date in a formatted matter so that:
hour-columns shows "dd hh:mm"(where mm obviously is 00 all the time)
day-columns shows: "dd.mm"
month-columns shows: "MM. YYYY"
Nevermind, I solved this issue. This was actually a bug fixed in this release:
https://github.com/amcharts/amcharts4/releases/tag/4.7.19
so updating my local amCharts4 files did the trick.
I still do not know how to change the tooltiptext and the grouping as described in my question

AWS set date to midnight

What is the best way to initialize a Date to midnight using AWS AppSync utility.
I need to know if we have something like this
var d = (new Date()).setUTCHours(0,0,0,0)
By using $util.time.nowEpochSeconds() , I am getting the epoch time but how do i identify the time difference that i need to add to set as midnight time
AppSync doesn't offer that capability through utils only yet and this is good feedback, I'll make sure the team sees this.
In the meantime, as a workaround, you could modify the date string to achieve what you need.
#set($time = $util.time.nowFormatted("yyyy-MM-dd/HH:mm:ss/Z"))
#set ($split = $time.split("/"))
#set ($midnight = $split[0] + " 00:00:00" + $split[2])
time: $time
midnight: $midnight
midnight epoch seconds: $util.time.parseFormattedToEpochMilliSeconds($midnight, "yyyy-MM-dd HH:mm:ssZ")
will print:
time: 2019-07-15/22:33:57/+0000
midnight: 2019-07-15 00:00:00+0000
midnight epoch seconds: 1563148800000

QCustomPlot display time in HH:MM:SS

I was wondering either it is possible in the QCustomPlot library to change display format of the data on one of the axis. In my application on the X axis I have time in seconds and I would like to display the steps in HH:MM:SS instead. As an alternative I am thinking of changing the display only from seconds to minutes to hours depending on the X lenght and updating the label from Time [s] to [min] to [hour]. But I would avoid that if its possible to do it the way I described. I Would appreciate all help!
When using:
customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
customPlot->xAxis->setDateTimeFormat("hh:mm:ss");
My timeline starts from hour 1 instead of 0:
Is there a way to fix this?
You can use setTickLabelType() and setDateTimeFormat:
plot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
plot->xAxis->setDateTimeFormat("hh:mm:ss");
The format string is built according to the the format string of QDateTime::toString().
// Создаем формат отображения дискретных отсчетов времени захвата мгновенного курса судна
QSharedPointer<QCPAxisTickerDateTime> dateTicker(new QCPAxisTickerDateTime);
// Установка формата отображения времени захвата мгновенного курса судна
dateTicker->setDateTimeFormat("hh:mm:ss");
// Передаем вектор подписей в график
m_QCustomPlot->yAxis->setTicker(dateTicker);