Can anyone translate this into python? [closed] - c

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.

Related

Convert a Time datatype column with values from hh:mm:ss.ffffff to hh:mm:ss:ff [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 days ago.
Improve this question
On Synapse Analytics how do we - Convert a Time datatype column with values from hh:mm:ss.ffffff to hh:mm:ss:ff
Here are the samples:
Actual
00:00:00.9900000
00:26:10.0200000
00:00:03.9800000
00:22:41.0400000
00:00:00.9800000
00:22:09.0300000
00:00:00.9900000
00:25:34.0200000
00:19:26.9800000
00:03:45.0200000

Need help using Regular expression [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 11 months ago.
Improve this question
I want to display the only the highlighted values (They are 9 digits). Can we do this using RegExp?
You can use regexp_substr(column1, '[0-9]{9}'). Below is an example:
select regexp_substr(column1, '[0-9]{9}') nine_digits
from (values
(';**260488570**;1;13.25;20339=22.99')
,('1293=::info::0,;**297100755**;1;2.86;20339=4.49')
,('1293=::info::0,;**338010030**;3;6.71;20339=2.69')
,('1293=::info::0,;**260142941**;1;2.38;20339=4.59')
,('1293=::info::0,;**370039059**;1;2.86;20339=3.79')
);
Result:
COL2
260488570
297100755
338010030
260142941
370039059

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.

How to convert this MS SQL numeric value to a date [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
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')
. . .

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.

Resources