Skip to main content
Tweeted twitter.com/StackDBAs/status/999328441798414338
Added the generic tag of the database management system of relevance; modified formatting; made some rewordings.
Source Link
MDCCL
  • 8.5k
  • 3
  • 31
  • 62

Getting year datepartDATEPART from unixUnix date MS SQL

OnIn my database, the dates are storedretained as days elapsed since/before 01/01/1970, which I understand to be a unixUnix date format., eg. today is 23rd May 2018 and the value is 17674.

I'm trying to run a selectselect statement against a column in a date table to show only the year.

If I run this: datepart(year, c.cko_date)

datepart(year, c.cko_date)

I get dates that are in the 1940s (they should be the last couple of years).

whenWhen I run select datepart(year, getdate()) it

select datepart(year, getdate()) 

it correctly tells me the date is 2018.

Any suggestions about what I'm doing wrong?

Getting year datepart from unix date MS SQL

On my database, the dates are stored as days elapsed since/before 01/01/1970 which I understand to be a unix date format. eg. today is 23rd May 2018 and the value is 17674

I'm trying to run a select statement against a column in a date table to show only the year.

If I run this: datepart(year, c.cko_date)

I get dates that are in the 1940s (they should be the last couple of years)

when I run select datepart(year, getdate()) it correctly tells me the date is 2018.

Any suggestions about what I'm doing wrong?

Getting year DATEPART from Unix date

In my database, the dates are retained as days elapsed since/before 01/01/1970, which I understand to be a Unix date format, eg. today is 23rd May 2018 and the value is 17674.

I'm trying to run a select statement against a column in a date table to show only the year.

If I run this:

datepart(year, c.cko_date)

I get dates that are in the 1940s (they should be the last couple of years).

When I run

select datepart(year, getdate()) 

it correctly tells me the date is 2018.

Any suggestions about what I'm doing wrong?

Source Link
Tom
  • 53
  • 3

Getting year datepart from unix date MS SQL

On my database, the dates are stored as days elapsed since/before 01/01/1970 which I understand to be a unix date format. eg. today is 23rd May 2018 and the value is 17674

I'm trying to run a select statement against a column in a date table to show only the year.

If I run this: datepart(year, c.cko_date)

I get dates that are in the 1940s (they should be the last couple of years)

when I run select datepart(year, getdate()) it correctly tells me the date is 2018.

Any suggestions about what I'm doing wrong?