I am trying to query a count of machines that are older than 5 years.
My machine data is in one tab with date time stamps in column K like "8/8/2008 8:08:08"
I have tried many different variations to get the query right... but my latest is like this
=query(RawDataMachines!B:K,"select count(K) WHERE K + INTERVAL 5 YEAR < NOW() label count(A1''")
Been trying to solve this issue for several days.
Any help would be appreciated.
Thanks in advance.
well try this and let me know....
select COUNT(K) from Machine where datediff(YEAR,k,getdate()) > 5;
datediff will return the number of years between the date k and the System Date.
Hope it Help's.
Related
I am try to write a Query function to automatically update consumer which purchased 5 day ago.
This result should alwasy be updated according to Today's date.
(Please use Query function to achieve this results, Because I need this Query method to apply into a more complex formula.)
Thank you so much.
https://docs.google.com/spreadsheets/d/1Y2rB910btqX-THHgNEylXuSN-aeKQv__siScoBTLZv8/edit?usp=sharing
In G2 I entered
=query(A2:B, "Where A <= date '"&TEXT(TODAY()-5, "yyyy-mm-dd")&"'", 0)
This should output all purchases done before 5 days ago as that seems to be the result you expect.
See if that works for you?
I know it's basic but I'm new to this. I just want to know how can I calculate the days duration of the two dates?
For example, I have my start date and time 11/22/2021 15:20:43 and end date and time 11/23/2021 14:51:29 I want to calculate the total days from start to end date and time.
Also, If start date time column is BLANK, return to count of days including date today.
Thank you
All you need to do is use the following formula: '=(C2-A2)'. This will give you the elapsed time between the two cells and display it as hours. You can take this calculation further by adding dates too. This is useful if you have work shifts that go more than 24 hours or that include two days within a single shift.
Assuming start dates in column A and end dates in column B, you can try
={"Duration in Days"; Arrayformula(if(len(A2:A) * len(B2:B), datedif(A2:A, B2:B, "d"),))}
Change ranges to suit and see if that works?
EXAMPLE
REFERENCES:
DATEDIF
there is a DAYS formula exactly for that purpose:
update:
=INDEX(IFERROR(1/(1/DAYS(
REGEXREPLACE(TO_TEXT(B1:B), "(.|..)[\/\-\.](.|..)[\/\-\.](.+) (.*$)", "$2\/$1\/$3"),
REGEXREPLACE(TO_TEXT(A1:A), "(.|..)[\/\-\.](.|..)[\/\-\.](.+) (.*$)", "$2\/$1\/$3")))))
demo sheet
I am trying to observe historical trends on customer acquisitions (new and returning) and am looking to use a formula to automate it for me.
Essentially, I am looking to determine the average amount of new customers we acquire on a specific day, specific week, and specific month. For example: what are the average customers we have acquired every Monday for the past 6 months, or what is the average number of customers we acquire the first week of every month?
Solution:
You can use the date operators in your QUERY statement to filter by month, week, or even day of week.
Examples:
every Monday for past 6 months
=query(A1:B, "select avg(B) where datediff(todate(now()),todate(A)) < 180 and dayofweek(A) = 2", 1)
first week of every month
=query(A1:B, "select month(A),avg(B) where day(A) <= 7 group by month(A) offset 1", 1)
You would need to tweak the sample queries to cover your data range and which columns do you need to average and compare.
References:
QUERY()
Query Language Reference | Scalar Functions
I have nodes with person label where i am storing their date of births too. For e.g.:
Person
{
name: Tim
D.O.B: 01/23/1990
}
Now I need to calculate his age as of current date and time ( i.e. either 27 years or 27 years, 10 months, 18 days ). So, could anyone let me know how could I perform it?
P.S.: I tried the following but seems to be missing something here :
WITH apoc.date.parse('01/23/1990', 'y', 'MM/dd/yyyy') AS startDate,
apoc.date.format(timestamp(),'y','MM/dd/yyyy') as endDate,
apoc.date.parse(endDate,'y','MM/dd/yyyy') as ed
RETURN ed - 4
The units supported by the APOC date format/parse/add/convert functions are: ms,s,m,h,d and their long forms. To work with months, you need to be working with a specific calendar system, and there is no common month unit of time to do conversions or additions, as different months are comprised of different days (then there's the leap days in February).
For years, you're going to have to go with day units and use division by 365.
Here's a query that will get you age in years and days.
WITH apoc.date.parse('01/23/1990', 'd', 'MM/DD/yyyy') as birth, apoc.date.convert(timestamp(), 'ms', 'd') as now
WITH now - birth as daysAlive
RETURN daysAlive / 365 as yearsAlive, daysAlive % 365 as daysExtra
If you want to get into months, it may be better to work with the month/year fields from the MM/DD/yyyy representation and pull some mathematics on those. I'll see about what we can for supporting that in APOC.
Some like
WITH apoc.date.parse('01/23/1990', 'y', 'MM/dd/yyyy') AS startDate
RETURN apoc.date.convert(timestamp() - startDate,"ms","d");
perhaps ?
Hope this helps.
Regards,
Tom
I need to grab the records for same day of the week for the preceeding X days of the week. There must be a better way to do it than this:
Transaction.find_by_sql "select * from transactions where EXTRACT(DOW from date) = 1 and organisation_id = 4 order by date desc limit 7"
It gets me what I need but is Postgres specific and not very "Rails-y". Date is a timestamp.
Anyone got suggestions?
How many days do you want to go back?
I have written a gem called by_star that has a dynamic finder suited for finding up to a certain number of days in the past. If the number of days was always a number you could use this finder:
Transaction.as_of_3_days_ago
If it was dynamic then I would recommend using something such as future or between, depending on if you have transactions in the future (i.e. time travel):
Transaction.future(params[:start_date].to_time)
Transaction.between(params[:start_date].to_time, Time.now)
AFAIK Rails has no any methods to do this by other way. So best, and faster, solution - build DOW index on date column and use your query.