how to get the current year from postgresql query, I tried like normal mysql query .But this is not working in postgresql?
SELECT YEAR(CURDATE());
try :
select to_char(now(),'YYYY')
you could also do this
select date_part('year', CURRENT_DATE);
In standard ANSI SQL (which is also supported by Postgres) this would be:
extract(year from current_date)
Related
Using SQL Server 2005
So I have a datetime field in SQL Server called 'dtJornada'
This query returns incorrect sintax. What would be the correct way of writing it?
select * from B
where dtJornada BETWEEN '2018-01-01' and '2018-01-04'
AND dtJornada NOT IN ['2018-01-01T14:25:10']
This is wrong:
dtJornada NOT IN ['2018-01-01T14:25:10']
The correct would be:
dtJornada NOT IN ('2018-01-01T14:25:10')
...although if you only want to filter out one value, why use NOT IN? You can just do:
dtJornada <>'2018-01-01T14:25:10'
2017-11-17 06:35:41.0000000 - this is a value of a column FileProcessDate in a SQL Server table. I am trying to build an incremental logic and I would like to use this date (directly) in Oracle to build that logic.
I am using the following query in Oracle
SELECT *
FROM EVENT
WHERE TIMESTAMP > TO_DATE('2017-11-17 06:35:41.0000000', 'MM/DD/YYYY HH:MI:SS')
But I am getting an error
not a valid month
You need to use correct timeformat:
SELECT *
FROM EVENT
WHERE TIMESTAMP>TO_TIMESTAMP('2017-11-17 06:35:41.0000000','YYYY-MM-DD HH24:MI:SS.FF')
DBFiddle Demo
I'm editing a query i build in ms sql.
I need to order the items on date, but that gives an error.
locations_aanvang gives 2012-08-12(yyyy-mm-dd). so i extend it to 2012-08-12 00:00:00 +1:00 for EST time.
So to order the i need to convert it to unix timestamp (right?).
The query is:
SELECT TOP 6 * FROM jd_lighthouses
WHERE locations_aanvang != ''
ORDER BY (SELECT DATEDIFF(s, '1970-01-01', locations_aanvang+' 00:00:00 +1:00')) DESC
And the error i get is:
[Microsoft][SQL Server Native Client 10.0][SQL Server]Conversion failed when converting date and/or time from character string.
What am i doing wrong? and can i do this easier?
Thanks in advance!
Kind regards,
Bram Hammer
Because we can'r clarify to question, only help is that:
if locations_aanvang is character type then you can avoid error changing code like this:
DATEDIFF(s, '1970-01-01', locations_aanvang + ' 00:00:00')
Since you use SQL Server Native Client 10.0 i assume you have SQL Server 2008 and DATE datatype. To get newest locations use:
ORDER BY CAST(locations_aanvang as DATE) DESC
Hmmm. Let me take a stab.
I think MS SQL warns against sorting by a column/calculation that
isn't directly in return results of your SQL. This is definitely so
in Oracle.
I'm assumming you can plug in a literal value for your
variable and it runs just fine?
I am trying to get teh current time as a unix timestamp from my MSSQL database.
In Mysql I could say something like:
SELECT id,
caregiver_id,
client_id,
week_no,
CURTIME() as Synch_Time
FROM dbo.Visits
But THERE is no CURTIME() function in T-SQL
Does anyone know of a solution?
Thanks
Kevin
You can use getdate() and do some calculations described here.
http://mysql.databases.aspfaq.com/how-do-i-convert-a-sql-server-datetime-value-to-a-unix-timestamp.html
getdate() is MSSQL specific, but current_timestamp() is more standard compliant. See similar question: Retrieving date in sql server, CURRENT_TIMESTAMP vs GetDate()
In SQL2012, use can convert to specific date and time types, e.g.
SELECT
Time = CONVERT(TIME, GETDATE()),
Date = CONVERT(DATE, GETDATE())
I can't remember how to do this in a TSQL query. It was a one-liner, good for testing before running DML. The query was something similar to SELECT IS_DBO() or SELECT IS(DBO).
You're probably looking for the IS_MEMBER function:
SELECT IS_MEMBER('db_owner')