Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Error: "syntax error at or near interval"
Join in question:
... LEFT OUTER JOIN usersession e ON a.userID = e.userID AND e.lastAction >= now() interval '-4h' * 1"
lastAction was created as lastAction timestamp NULL DEFAULT NULL
The idea is, to return some nils if the session's timestamp is 4 hours older than the current time.
No idea what the deal is here, never had to compare timestamps before either.
If you want records for the last 4 hours you need:
now() - interval '4 hours'
instead of
now() interval '-4h' * 1
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 months ago.
This post was edited and submitted for review 3 months ago and failed to reopen the post:
Needs details or clarity Add details and clarify the problem by editing this post.
Improve this question
(hour(date_column ) * 4)
+ ifn(minute(date_column ) = 0, 0
, ifn(minute(date_column ) <= 15, 1
, ifn(minute(date_column ) <= 30, 2
, ifn(minute(date_column ) <= 45, 3, 4))))
as date_no
What are the equivalents of these functions in PostgreSQL?
I am trying to extract value based on 15 mins interval in an hour.
It would help if you explained your goal and current logic in a bit more detail, but for now it looks like this would suffice:
select extract('hours' from date_column) * 4
+ ceil(extract('minutes' from date_column) / 15) as date_no
from your_table;
extract() is used in PostgreSQL for the same thing hour() and minute() are in SAS.
You can use CASE the exact same way you would in SAS but there's no IFN() counterpart.
CEIL() works the same in both, so you could also shorten your SAS version replacing all the IFN's.
You're effectively binning date/times, so you could look into date_bin(). Similar effect can probably be achieved in SAS through the use of INTNX() or plain ROUND() (1, 2).
Demo
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
How to convert '02-3月 -21' to date 21-03-02 00:00:00? in postgresql or kettle
I think a simple replace can do the trick here. Just replace the Chinese character 月 with nothing and format it.
SELECT TO_TIMESTAMP(REPLACE ('02-3月-21', '月', ''),'DD-MM-YY');
// output: 2021-03-02 00:00:00+00
SELECT TO_CHAR(TO_TIMESTAMP(REPLACE ('02-3月-21', '月', ''),'DD-MM-YY'), 'YY-MM-DD HH24:MI:SS')
// output: 21-03-02 00:00:00
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
how would I go about selecting data from only Sundays in 2019 in Postgres?
I think Sundays are a 0 but I am unsure as to how to query it like that.
I am selecting from a preexisting table that contains timestamp strings like 2020-09-03 02:11:60, so basically I want to select all the timestamps that occurred in 2019 in my table usermetrics in the column timestamp.
You have two requests.
The first to find timestamps in 2019:
SELECT
*
FROM
usermetrics
WHERE
timestamp BETWEEN '01/01/2019'::date AND '01/01/2020'::date
The second to find those that occurred on Sundays:
SELECT
*
FROM
usermetrics
WHERE
timestamp BETWEEN '01/01/2019'::date AND '01/01/2020'::date
AND
extract(DOW FROM timestamp) = 0;
01/01/2020::date is used as 12/31/2019::date would miss timestamps that occurred after midnight.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a table "empdata" it contains fields create date, last modified date, emp id. In order to check count am running query "select count(*) from empdata". Now I need query where I have to get results till yesterday's date.
for example:
select count(*) from empdata
output: 23
select count(*) from empdate ( I need condition here for yesterday's date)
output:20
Note: **I need to use this query in java program so I cannot give yesterday's date in query. Java program will be running daily so date gets* changed daily.*
Use this query to get the results, te condition you've asked should be
where create_date < current_date()
select count(*) from empdata where create_date<current_date()
You have mentioned that you want to run this program in java, Try jdbc
http://www.tutorialspoint.com/jdbc/
edit:
use CURRENT DATE instead of current_date() in the above query for db2
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am trying to calculate the number of days between two datetimes in MATLAB.
startDate = datetime('12-Nov-2014 00:00:00','InputFormat','dd-MMM-yyyy HH:mm:ss')
endDate = datetime('18-Feb-2016 00:00:00','InputFormat','dd-MMM-yyyy HH:mm:ss')
Using diff I get the following result:
diff([startDate endDate])
ans =
11112:00:00
I am expecting a value of about 500 days not 11000.
If you can avoid to use datetime:
startDate = datenum('12-Nov-2014 00:00:00');
endDate = datenum('18-Feb-2016 00:00:00');
days = endDate-startDate
days =
463