Save Date on SQL Server with wrong timezone - sql-server

I have this:
Clock = Date.now();
this.newReport.DateTime = new Date(this.Clock);
Client side the date is ok: Mon May 20 2019 19:08:34 GMT+0200
But on SQL Server it is save with time 17:08
Why?
Thanks

It looks like that's the same date, when you include the Timezone offset. If the "client side" date is GMT +0200, then the datetime stored should be 17:08:34 (as GMT time).
You're not including much detail, but I expect that you are wanting to save the time as local time. You could either convert the time to Localtime before saving it (and lose the additional information about the timezone), or save the GMT offset along with the date and time so that you could have both available if you wanted to convert it back to localtime later.

Related

Add timezone offset retroactivly to SQL Server datetime entries

We have our time saved without a timezone offset inside our SQL Server database. The time is actually Central Europe Standard Time but due to no timezone offset in the time string it is treated as UTC. This now creates a bunch of problems regarding daylight saving times.
My question would be: is there a way to retroactively convert the Time with offset to the correct CEST Time.
For example my time string in my database is '2022-10-30 02:00' and should be converted to '2022-10-30 00:00+2' as well as '2022-10-30 03:00' to '2022-10-30 01:00+1'.
There is an option to convert a datetime object to another timezone with "AT TIME ZONE" but this didn't help much due to the date objects being treated as UTC in the database, but we need to convert them to the UTC+[offset] format. Also due to the daylight saving time changing timezone offsets during the year, we can't subtract the timezone offsets with a set value.

In IICS (Informatica cloud)how can I convert the source (snow flake)field which is in time zone UTC to time zone GMT

I have source data coming from snowflake and has date field with UTC time Zone, and I want to convert to GMT , the time zone which Informatica cloud uses for built in variable
$Lastruntime .
Example
Update_at field from source has 2022-08-13 11:31:52076(timestamp_nts(9)
I want to convert this field to GMT
Thanks

how to convert UTC date/time into MDT and military time for react application?

I am trying to convert UTC into MDT (mountain time) format. I am not sure which moment format require to convert date time into MDT. i tried moment.fromOADate(41493) but not working. TIA!
Mountain time is GMT -6, so you should be able to use moment().utcOffset(-6)
https://en.wikipedia.org/wiki/Mountain_Time_Zone
https://momentjscom.readthedocs.io/en/latest/moment/03-manipulating/09-utc-offset/
If you're worried about accounting for daylight savings time and can't just subtract 6 hours, you might also look into the moment.js timezone library.
You could say something like is described here and do var zone = moment.tz.zone('America/Chihuahua') (this is mountain time), then get your time offset with zone.parse(utcTimestamp)

moment to date object timezone issue

I have a moment.js object generated from fullcalendar in BST that looks like this:
console.log(momentSelected)
//Moment {_isAMomentObject: true, _isUTC: true, _offset: 0, _locale: f, _d: Tue May 03 2016 01:00:00 GMT+0100 (BST)…}
I don't want a BST time but a UTC time that looks like this:
console.log(momentSelected.format('YYYY-MM-DD HH:mm Z'));
//2016-05-03 00:00 +00:00
Now I need to convert it into a Date object:
$scope.date = new Date(momentSelected.format('YYYY-MM-DD HH:mm Z'));
console.log($scope.date);
//Wed May 04 2016 01:00:00 GMT+0100 (BST)
The last output is wrong... I want Wed May 04 2016 00:00:00+00:00 (UTC)
You can create a Date object using the toDate function on the moment object.
$scope.date = momentSelected.toDate();
However, you must recognize that the nature of the Date object is that it will always represent UTC internally, and its toString function will always reflect the local time zone where the code is running.
If your local time zone is UK (alternating between GMT and BST for daylight saving time), then it is impossible to get (UTC) time in the string produced by console.log($scope.date);, regardless of how you created that date.
This is why it is better to use moment's format function and display that string directly. A moment can reflect UTC, local time, and other time zones. A Date object cannot.
Also, you should pay no attention to the underscore-prefixed internal fields of a moment object. Use the public API instead. See the moment user guide.

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

Resources