Convert like America/New_York in MySQL server 2008 R2 server - sql-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

Related

What is the way to use universal SQL date format in MS Access?

In SQL the universal date format is YYYYMMDD
For example. To search records greater than 15 Jan 2021 I write:
Where Datecol>='20210115'
This works irrespective of US or UK machine.
Is there an equivalent of this in the MS Access database?
Access uses octothorpes and separators:
Where Datecol >= #2021/01/15#

Get date at a provided timezone with daylight savings using MSSQL query

I am using SQL Server 2014
Currently, I am using MSSQL function:
format(TODATETIMEOFFSET(("[dateColumn]",'-6:00'),'MM/dd/yyyy')
However, this will not apply Daylight savings.
How can i achieve it?
Please help
This answer was provided before information was received that the OP was using SQL Server 2014 (which I have now added to their tags). I have left the answer here, however, as it will likely be helpful for future readers using a more recent version of SQL Server.
UTC -6 will always be UTC -6; it doesn't change for daylight savings and become UTC -5. Timezones like GMT (UTC+0) and EST (UTC-5) change to BST and EDT but then they also respectively become UTC +1 AND UTC -4. You're providing a literal number so the value will always be UTC -6.
What you are likely looking for is AT TIME ZONE (AT TIME ZONE (Transact-SQL), which was introduced with SQL Server 2016. For example:
--Returns 2018-01-01 18:00:00 -06:00
SELECT CONVERT(datetime2(0), '2018-01-01T18:00:00') AT TIME ZONE 'Central Standard Time';
--Returns 2018-07-01 18:00:00 -05:00 (changes to -5, due to daylight saving)
SELECT CONVERT(datetime2(0), '2018-07-01T18:00:00') AT TIME ZONE 'Central Standard Time';

Can anyone help me identify this timestamp format?

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

Excel Power Query - convert date time from UTC to Local

I'm connecting to an MS SQL database via Power Query (Version: 2.10.3598.81) in Excel 2010.
My dates are stored in UTC in the database, however I would like to show them as local in the spreadsheet.
DateTimeZone.From() - converts to a DateTimeZone type but assumes the input date is in the Local timezone. This is the exact opposite of what I want.
DateTimeZone.ToLocal() - gives an error, I think because there's no timezone information in the source date.
Local in my case is Australian EST, however it would be great if Excel just picked up the local timezone. (It appears to do this already)
I think I've discovered the answer.
The function DateTime.AddZone() which I thought was used to convert between timezones is actually used to add timezone information to an existing date. If your date is UTC you would use DateTime.AddZone([date_created],0) and if your date was already in AEST then you would use DateTime.AddZone([date_created],10).
So I can now use:
DateTimeZone.ToLocal(DateTime.AddZone([date_created_UTC],0))
and Power Query will correctly convert my date created from UTC to AEST (or whatever is local).

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.

Resources