0

I used the below query to extract the weekday by providing datetime that works fine but I need to extract weekday from a Millisecond column

If TIMEVAL is DATETIME datatype then below one works:

SELECT DATEPART(dw,TIMEVAL) FROM Student;

If TIMEVAL is in Big Int (Millisecond) then the same query doesn't work

So, how can I get the WEEKDAY by using DATEPART for a column which contains MILLISECOND?

Shahzad Barkati
  • 2,532
  • 6
  • 25
  • 33
Raamesh Keerthi
  • 769
  • 1
  • 7
  • 12
  • see this : http://stackoverflow.com/questions/12524537/convert-utc-milliseconds-to-datetime-in-sql-server to convert milliseconds to datetime – Raphaël Althaus Nov 30 '15 at 07:59
  • I found it here is the query to get the weekday SELECT DATEPART(dw, (DATEADD(ms, DATEDIFF(ms, GETUTCDATE(), GETDATE()),DATEADD(ss, TIMEVAL/1000,'1970-01-01')))) FROM Student – Raamesh Keerthi Nov 30 '15 at 09:53

1 Answers1

0

Here is the answer for my above question

SELECT DATEPART(dw, (DATEADD(ms, DATEDIFF(ms, GETUTCDATE(), GETDATE()),dateadd(ss, TIMEVAL/1000,'1970-01-01')))) FROM Student

Raamesh Keerthi
  • 769
  • 1
  • 7
  • 12