Is it possible to make a google datastore GQL query with a comparison on the current DateTime?
Example:
select * from MY_KIND where created_at < DATETIME.NOW
I've seen anything about that on any post or google documentation:
https://cloud.google.com/datastore/docs/reference/gql_reference
I need to make an operation on data older than 30 days.
You can use an alternative approach by trying to fetch entries after a particular date.
SELECT * FROM Entry WHERE date > DATETIME(yyyy,mm,dd)
The right-hand side of a comparison can be one of the following:
A datetime, date, or time literal, with either numeric values or a string representation, in the following forms:
DATETIME(year, month, day, hour, minute, second)
DATETIME('YYYY-MM-DD HH:MM:SS')
DATE(year, month, day)
DATE('YYYY-MM-DD')
TIME(hour, minute, second)
TIME('HH:MM:SS')
Hope this answers your question!!
Related
I'm looking for a way to select in Amazon Athena a selection of hours for different days.
I have a table with visitors to a specific location for every half hour, I now want to know the visitors during opening hours for a store, for the period of a month.
I now used this but doing it day by day is quite a job.
Was trying to split datetime with Datepart but didn't get it working properly.
SELECT visitors, datetime
FROM corrected_scanners_per_half_hour
WHERE datetime
BETWEEN CAST('2020-05-25 08:30:00' AS timestamp)
AND CAST('2020-05-25 17:30:00' AS timestamp) ;
Here you go
select visitors, date(datetime)
from corrected_scanners_per_half_hour
where date_format(datetime, '%H:%i') between '08:30' and '17:30'
I'm using bigquery integrated with Firebase Analytics and I'm trying to query the difference between an event_timestamp and current timestamp in hours. I'm doung something like this:
SELECT TIMESTAMP_DIFF(event_timestamp, CURRENT_TIMESTAMP(), HOUR)
FROM my-firebase-analytics-table
WHERE event_name = 'session_start'
With this query I'm getting an error in TIMESTAMP_DIFF(event_timestamp, CURRENT_TIMESTAMP(), HOUR). The error is:
No matching signature for function TIMESTAMP_DIFF for argument types: INT64, TIMESTAMP, DATE_TIME_PART. Supported signature: TIMESTAMP_DIFF(TIMESTAMP, TIMESTAMP, DATE_TIME_PART)
For what I could get for the tests I made is that the event_timestamp field is not an TIMESTAMP field. Is their a way I can transform it into a TIMESTAMP?
Usually if it is a INT64 - it is presented in milliseconds from epoch
To convert to timestamp - use TIMESTAMP_MILLIS(int64_expression) as in below example
#standardSQL
SELECT TIMESTAMP_DIFF(TIMESTAMP_MILLIS(event_timestamp), CURRENT_TIMESTAMP(), HOUR)
FROM `project.dataset.my-firebase-analytics-table`
WHERE event_name = 'session_start'
Obviously, it can be INT64 for seconds or microseconds - so you will use respective counterparts in this case - TIMESTAMP_MICROS or TIMESTAMP_SECONDS
I've integrated my Firebase project with BigQuery. Now I'm facing a data discrepancy issue while trying to get 1 day active users, for the selected date i.e. 20190210, with following query from BigQuery;
SELECT COUNT(DISTINCT user_pseudo_id) AS 1_day_active_users_count
FROM `MY_TABLE.events_*`
WHERE event_name = 'user_engagement' AND _TABLE_SUFFIX = '20190210'
But the figures returned from BigQuery doesn't match with the ones reported on Firebase Analytics Dashboard for the same date. Any clue what's possibly going wrong here?
The following sample query mentioned my Firebase Team, here https://support.google.com/firebase/answer/9037342?hl=en&ref_topic=7029512, is not so helpful as its taking into consideration the current time and getting users accordingly.
N-day active users
/**
* Builds an audience of N-Day Active Users.
*
* N-day active users = users who have logged at least one user_engagement
* event in the last N days.
*/
SELECT
COUNT(DISTINCT user_id) AS n_day_active_users_count
FROM
-- PLEASE REPLACE WITH YOUR TABLE NAME.
`YOUR_TABLE.events_*`
WHERE
event_name = 'user_engagement'
-- Pick events in the last N = 20 days.
AND event_timestamp >
UNIX_MICROS(TIMESTAMP_SUB(CURRENT_TIMESTAMP, INTERVAL 20 DAY))
-- PLEASE REPLACE WITH YOUR DESIRED DATE RANGE.
AND _TABLE_SUFFIX BETWEEN '20180521' AND '20240131';
So given the small discrepancy here, I believe the issue is one of timezones.
When you're looking at a "day" in the Firebase Console, you're looking at the time interval from midnight to midnight in whatever time zone you've specified when you first set up your project. When you're looking at a "day" in BigQuery, you're looking at the time interval from midnight to midnight in UTC.
If you want to make sure you're looking at the events that match up with what's in your console, you should query the event_timestamp value in your BigQuery table (and remember that it might span multiple tables) to match up with what's in your timezone.
Does anyone know on what basetime Evernote calculates datetime?
I need to directly deal with the notes table in the Evernote SQLite DB and the documentation refers people to the SQLite manual https://www.sqlite.org/lang_datefunc.html
This stored time 736012.8334375 should yield 2016/02/18 21:00
I've tried multiple variants such as
select datetime(((((736012.8334375)*1000/60)/60)/24), 'unixepoch'), datetime(((736012.8334375)), 'unixepoch'), datetime(736012.8334375, 'unixepoch'), strftime('%s', 'now'), strftime('7736012.8334375', 'unixepoch'), datetime((736012.8334375 *1000), 'unixepoch')
giving
"1970-01-01 23:39:46","1970-01-09 12:26:52","1970-01-09 12:26:52","1464341058",,"1993-04-28 16:00:33"
This Excel formula
=((((736012.8334375)*1000/60)/60)/24)+DATE(1970,1,1)+(1/24)
gets closer with
4/28/93 5:00 PM
but still a bit out.
What am I doing wrong?
Here's the formula I arrived at for determining the real date from Evernote's dates:
unixTime = (EvernoteTime * 86400) - 62135683200
I've tested this with a few time zones by exporting data from the Evernote app to html and hand-verifying the times match.
I'm not sure where the 62135683200 comes from. It's not quite the difference between unix epoch and year zero, but after arriving at the correct value I stopped trying to figure it out.
I am having graph database which is collection of events and attendees.
I store start_time property of an event as unix timestamp so that its easier to search upcoming events just by comparing unix timestamp.
Now the problem is by mistake I stored date string as start_time value in few events and now I can not compare date string with unix timestamp, and thats why query returns no events.
How can I compare data type of start_time property before comparing its value?
Please guide me the correct way to achieve my objective..
You can implicitly check for the property type using the toInt function and comparing with the value. To convert all string style start_time to their numeric variant:
MATCH (n)
WHERE has(n.start_time) and (toInt(n.start_time)<>n.start_time)
SET n.start_time = toInt(n.start_time)
In case of a lot of nodes use SKIP and LIMIT to work on reasonable batches.
This is how I solved this problem.
"START attendee=node:attendee('user_id:100001195447969') MATCH (attendee)-[:friends_with]-(friend)-[:attending]-(event) WITH event,attendee as user, count(distinct friend.user_id) as count WHERE REPLACE(str(event.start_time),"-","") = str(event.start_time) AND count >= 1 RETURN event.start_time;"
So now it does not give me events having start_time like "2014-06-05 10:00:00". And I can compare start_time of rest of the events.
I don't know if this would work, but could you compare the value to the value wrapped in a str function? It may not work if the string properties are formatted like unix timestamp, but it's worth a try.
MATCH (e:Event) WHERE e.start_date = str({e.start_date}) RETURN e;