Can anyone help me identify this timestamp format? - sql-server

I am importing information from an Oracle database on an AIX machine into SQL Server 2008r2. I inherited this process from the previous DBA. The timestamp comes in the following format: 4170180534, which, based on the conversion function in the executable, converts to the following:
417 = year (2017)
018 = days since beginning of year (018 converts to Jan 18)
0534 = time HH:mm
I need to provide maintenance on the conversion function (the previous DBA retired in 2016, so the date conversion function only works through the end of 2016).
Can anyone tell me exactly what this timestamp format is? I assume the '4' stands for the century, but it would be nice to know for sure what the first digit of the value actually is.

4should stand for weeks since start of year
format for that would be
(weeks since 1st jan, 2last digits of year, days since 1st jan, hours, minutes)
WW IY DDD HH MI

Related

casting INT to Datetime date is 2 days off

So I am parsing out a large text field with several dates in it. the date format comes out like "44445" which should be "9/6/2021" but when I convert to datetime in Microsoft SQL Server 2019 i get "9/8/2021" I found that every date that I convert is 2 days off. I can of course just do a -2 before converting to make sure I get the right date but I found this really odd and wondered if anyone knew why this was happening and if I am doing something wrong
cast(44445 as datetime) result 2021-09-08 00:00:00.000
if I put the same date in excel I get "9/6/2021" which is the correct date
I found something online about excel calculating 1900 as a leap year and therefore having a different date but excel seems to be correct and SQL statement seems to be wrong so I don't know...

Convert String to datetime in SQL Server 2008

How will I convert date in the format Sat Mar 29 00:00:00 EST 1975 to datetime in TSQL?
I get the date in this format from an old table which defined the date of birth column as NVARCHAR and stores the data as Mon Jun dd hh:mm:ss GMT yyyy format. I need to read another table which has the dob in datetime using this value.
So basically I want to convert, say Sat Mar 29 00:00:00 EST 1975 to 1975-03-29 00:00:00.000
Is there a way in T-SQL to do this conversion? I tried the CONVERT function, but I am unable to locate the correct 'style' to use.
Examining the data format, it appears to be a fixed length string.
The first portion is the day of week, which can be discarded as it isn't needed for parsing. Next you have the month and day information, which we need. After that is the time, which can be retained or discarded depending on whether you want a date or datetime as output.
Since you are looking for a date of birth, the time zone information can most likely be safely discarded.
Finally, there is the year.
If we eliminate the day of week and the time zone, sql server will parse the rest of the string with no problem.
I recommend cast(substring(#difficultTime,5,7) + substring(#difficultTime,25,4) as date), where #difficulteTime is the column name you are converting.
If you wanted to retain the time information, the following format will work cast(substring(#difficultTime,5,16) + substring(#difficultTime,25,4) as datetime)
This assumes that your strings will be of a fixed length. The first conversion shown eliminates the day of week, the time, and the time zone from the string, leaving a parseable date.
The second conversion eliminates the day of week and the time zone, leaving a parseable datetime.

Convert like America/New_York in MySQL server 2008 R2 server

13:30:00 Friday April 19, 2013 in America/New_York converts to
09:30:00 Friday April 19, 2013 in America/Anchorage
Convert like this in SQL Server 2008 R2.
using select query.
Please help me on this.
Thanks,
we will convert in java wright from "America/New_York" to America/Anchorage like way i need a select query to convert EST time to other time zones..please not the time zone cannot be given like MET,GMT and all...
PLEASE NOTE:- All time zones will only be like plain text America/Anchorage
You are looking for this function:
CONVERT_TZ(dt,from_tz,to_tz)
CONVERT_TZ() converts a datetime value dt from the time zone given by from_tz to the time zone given by to_tz and returns the resulting value. Time zones are specified as described in Section 10.6, “MySQL Server Time Zone Support”. This function returns NULL if the arguments are invalid.
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_convert-tz

Converting number to date in oracle

I have a numeric field in my Oracle database that represents the number of days since Dec 28, 1800. However I am trying to select it (for another application) as the current date it represents. I'm not too familiar with Oracle commands (I'm used to SQL), so I was wondering if anyone could provide some assistance. Thanks.
ex: 77650 = Saturday, August 3, 2013
Firstly, get this out of the way, your life would be easier if you stored dates in a date data-type.
However, to answer your question to add days to a date in Oracle you can use the + operator.
Firstly though you have to have a date so I'll convert the 28th December 1800 into a date using to inbuilt to_date function then add the number. In your case you would want:
select to_date('1800/12/28','yyyy/mm/dd') + 77650 from dual
I've set up a little SQL Fiddle to demonstrate for you.

Time in UTC HEX format. How to convert to normal time?

I have some application for dataaquistion from 3rd party developer company. The timestamps are saved by the app to a unknown format. The column in the MSSQL 2008 database is named "UTC" and datatype is varchar(32).
Timestamp sample:
2455832.07550638:000000A9
2455832.07552953:00000173
2455832.07555267:0000023B
2455832.07557582:00000303
Is anybody know how to convert via MSSQL query ?
I don't know about MSSQL, but your timestamp format (the part to the left of the colon) looks like Julian dates: the number of (fractional) days elapsed since noon, Jan 1, 4713 BC (UT). From the number of decimal digits, the time resolution seems to be about one millisecond. You can convert Julian dates to a Unix timestamp simply by unix_timestamp = (jd-2440587.5)*86400. I don't get the meaning of the second field (the hexadecimal part), but I guess it's not part of the timestamp.

Resources