How to convert this MS SQL numeric value to a date [closed] - sql-server

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 5 years ago.
Improve this question
Should be an easy convert, but cast and convert are failing me.
The value I am trying to convert is: 1509180600
Other examples are 1572256200, 5150938920
I have a very large number of records and many fields where dates have been stored like this. The system is being replaced, which means thankfully, this problem will go. But need to know what the values are before wiping them!

This is probably a Unix timestamp. You can convert it by adding seconds to 1970-01-01:
select dateadd(second, col, '1970-01-01')
. . .

Related

Row numbers for consecutive dates for a given activity [closed]

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 4 days ago.
Improve this question
I need to return row numbers for consecutive dates for each activity.
enter image description here
I have tried row_number() over(partition by) but cannot seem to get the right row numbers against the consecutive dates for the activity type. This is what I am trying to return:
enter image description here

my project has diffrent result every time [closed]

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 2 years ago.
Improve this question
I wrote this code in my project but every time i run it the answer is diffrent.
]1
Initialize sum with a value of 0. The reason it is different every time is you are calling sum which you never assigned a value. Anything could be in memory where sum is stored, which is why your results are inconsistent.

Can anyone translate this into python? [closed]

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 5 years ago.
Improve this question
dow(m,d,y) {
y-=m<3;
return(y+y/4-y/100+y/400+"-bed=pen+mad."[m]+d)%7;
}
The function's purpose is to find what day(Su-Sa) will the provided date(1-31) land on in any given month and year.
I'm not sure how this function works because it was written in C. Mostly I don't know what
the y-=m<3 is for, or what the "-bed=pen+mad." does (is this just a string?).
here is my source: https://cs.uwaterloo.ca/~alopez-o/math-faq/node73.html
Just use the python datetime module:
import datetime
dayOfWeek = datetime.datetime(y, m, d).weekday()
dayOfWeek will then be an integer between 0 and 6 corresponding to Monday - Sunday.
Have a look at the docs for more details.

How to calculate birth year in SQL Server [closed]

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 7 years ago.
Improve this question
In TSQL, how can the year of birth be calculated?
I have tried datediff options but to no avail.
Thanks in advance for any thoughts.
If you only have age, you have already lost information. you can never know for sure the year of birth. This will approximate the YOB
dateadd(yy,-Age,CURRENT_TIMESTAMP)
You could slightly improve the accuracy of this guess by trying to adjust for the probability of whether the individual has had a birthday this year.
dateadd(yy,case when month(current_timestamp) <= 6 then 0 else 1 end-Age,CURRENT_TIMESTAMP)
You will want to substitute CURRENT_TIMESTAMP for the time that the age metric was acquired if you are retro-applying this to an existing dataset (assuming that data is available).
Above all, I would recommend changing your process to capture date of birth upfront if possible.

How do I convert an int to hexadecimal and then put it as a string format? [closed]

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
For example, let's say I have the decimal number 10.
I want to be able to go form an integer of 10 to a string of "0a".
How do I do that?
Note: I don't want anything printed out.
You can use sprintf to represent a numeric value in hexadecimal format:
sprintf(buff, "%0.2x\n", 10)
Take also a look at dmckee's comment on int/hexadecimal misunderstanding.

Resources