How insert value in new column in google sheets using query funtion - datetime

I have a column shown in the figure I want to add a new column based on the condition morning (6 AM-12 PM), afternoon (12:00:00–18:00:00), evening (18:00:00 24:00:00), and night (24:00:00–06:00:00) so if time is 07:00:00 then the value in my column should be morning. I want to add value to google sheets using the query function.

use:
=IFNA(INDEX(VLOOKUP(A1:A*1, {
0, "night";
"6:00:00" *1, "morning";
"12:00:00"*1, "afternoon";
"18:00:00"*1, "evening"}, 2, 1)))

Related

Data frames and datetimes [duplicate]

This question already has answers here:
Extracting time from POSIXct
(7 answers)
Closed 8 months ago.
I have a dataset that I’m working with and I’m trying to change the format of my time column. The current format reads like this, example: “2022-05-23 23:06:58”, I’m trying to change this to only show me the hour times and erase the dates.
Other info: I want to make this change within my data frame, not just random times. I want to change over 100,000 rows so I need a function or solution that will do so. Tidyverse, Lubridate, Format, etc. Thank you guys.
Edit: There was one thing I may not have articulated fully, I wanted to keep the exact time and nothing else. so ‘23:48:07 would’ be how I’m looking for it not just the our. I need it so I can eventually subtract the time passed between two columns. You get me?
Try this
for the first question here is the code to convert to the hour of the day
your_time<-format(as.POSIXct(your_time), format = "%H:%M:%S")
#which gives "23" hours of the day
Since you want to apply on a large dataset we use this below
large_df%>%
mutate(Hour = format(as.POSIXct(Datetime), format ="%H:%M:%S"))
where the large_df is your large dataset worth over 100,000 records
The mutate will open another column for the result which is named the Hour column
and the Datetime is the DateTime column in your large_df dataset
Is the time as a string ok? Cause then you can use substr to extract the hour and minutes like so:
time <- c("2022-05-23 23:02:58", "2022-05-23 13:52:58", "2022-05-23 03:31:58", "2022-05-23 09:09:58")
n <- nchar(time)
hour <- substr(time, n - 7, n - 3)
Just time with your 100.000 row time column
library(data.table)
hour("2022-05-23 23:06:58") # 23

Setting start date parameter to display in SSRS report as Day1

Is there a way to set the Start Date parameter to 1, next day would be 2, next day would be 3.
I would like to group on this and do day/week/month/year summaries.
I want to change the report that is attached to be a matrix report displaying days instead of dates starting with day 1 for whatever day is chosen. To go across the columns in a matrix and then aggregate those calculations to week/month/year summaries
Current Report by Date
I used the DAY function in SSRS. DAY(Fields!created_date.Value)

How to add Two Columns (Date/Time) Together in Tableau

I have a dataset which was imported from Excel to Tableau. In Excel the data is listed as "8:15:00 AM". When it's imported into Tableau it's now Date & Time as "12/30/1899 10:45:00 AM".
What I'm trying to perform is an addition problem between two date & time columns. An example being:
Sleep: 12/30/1899 10:45:00
Eating: 12/30/1899 00:45:00
Sleep + Eating which should yield 10:40 + 00:45 = 11:30
After much googling and video watching, I have not found a solution.
Creating a calculated as such should solve the problem:
DATEADD(
'hour', DATEPART('hour', [Eating]), DATEADD(
'minute', DATEPART('minute', [Eating]), DATEADD(
'second', DATEPART('second', [Eating]), [Sleep])))
From there, the time display of the field can be adjusted as necessary:
Right-click field name > Default Properties > Date Format
You can achieve the desired result by creating three calculated fields. Lets call one of the calculated field [hours] and another one [minutes]. A third field will use the values from [hours] and [minutes] in order to properly display the results. Let's call this third field [Sleep + Eating].
To create [hours]:
//[hours] calculated field
DATEPART('hour', [Sleep])+ DATEPART('hour', [Eating])
To create [minutes]:
//[hours] calculated field
DATEPART('minute', [Sleep])+DATEPART('minute', [Eating])
At this point [hours] and [minutes] are just the sums of the integer values from [Sleep] and [Eating]. To display these sums in the format you have requested, you'll need to have a third calculated field that concatenates hours and the minutes, and is also able to handle a situations where the minutes add up to more than 60, or when the minutes add up to less then 10.[Sleep + Eating] calculated field will achieve this.
Here is the [Sleep + Eating] calculated field:
//[Sleep + Eating] calculated field
IF [minutes]< 10 THEN STR([hours])+":0"+STR([minutes])
ELSEIF [minutes]< 60 THEN STR([hours])+":"+STR([minutes])
ELSEIF [minutes]>= 70 THEN STR([hours]+1)+":"+STR([minutes]-60)
ELSE STR([hours]+1)+":0"+STR([minutes]-60)
END
Other solutions that try to treat your data like a date field (See #Daniel Sims answer) could be problematic if the hours sum to greater than 23, the result will add a day. For example, lets say you had these values in Excel:
If you use my solution, the result will be 25:02. If you use #Daniel Sims answer, the result would be 12/31/1899 1:02 :00 AM, which I don't think is what you want.

Apache Drill: Group by week

I tried to group my daily data by week (given a reference date) to generate a smaller panel data set.
I used postgres before and there it was quite easy:
CREATE TABLE videos_weekly AS SELECT channel_id,
CEIL(DATE_PART('day', observation_date - '2016-02-10')/7) AS week
FROM videos GROUP BY channel_id, week;
But it seems like it is not possible to subtract a timestamp with a date string in Drill. I found the AGE function, which returns an interval between two dates, but how to convert this into an integer (number of days or weeks)?
DATE_SUB may help you here. Following is an example:
SELECT extract(day from date_sub('2016-11-13', cast('2015-01-01' as timestamp)))/7 FROM (VALUES(1));
This will return number of weeks between 2015-01-01 and 2016-11-13.
Click here for documentation

Get RowCount With Date Comparasion in SSRS

I am new to SSRS.
I have a dataset, my dataset brings data from a stored procedure.
one of the parameters of my sp is StartDate and another one is EndDate. Their type is datetime
And the table has a dateTime Column called Date.
I have two gauges and I wanna bind integer values to my gauges.
First one is the count of rows where Date < DateAdd(DateInterval.Hour,24,StartDate)
and te second is count of rows where Date > DateAdd(DateInterval.Hour,24,StartDate)
How will I write the exact script. Whatever I wrote is not working.
I appreciate any help, thanks.
You need to set the gauge Pointer value as something like:
=Sum(IIf(DateDiff(DateInterval.Day, Parameters!StartDate.Value, Fields!Date.Value) >= 1
, 1
, 0))
This is counting rows where the time difference is less than a day compared to the parameter StartDate. Just change it slightly to get those where the difference is at least a day:
=Sum(IIf(DateDiff(DateInterval.Day, Parameters!StartDate.Value, Fields!Date.Value) >= 1
, 0
, 1))
Worked fine for me in a quick test:

Resources