Azure Data Factory data flow timezone conversion problem - azure

I was trying to convert a timezone from CST to UTC inside a data flow. A quick google gave me that CST is in UTC-6:00, so it should add 6 hours.
The following derived column function for some reason only added 5 hours:
toUTC(localDatetime, 'CST')
Moreover, CurrentUTC('CST') Gave me the correct 6 hours difference, so I had to rewrite this function like this:
LocalDatetime + hours(toInteger((currentUTC('CST') - currentUTC()) / 1000 / 60 / 60))
// Minus between timestamps gives difference in milliseconds
Is this intended behavior? I am worried that when the timezone "shifts" this code will break, so using toUTC would be the best solution, but for some reason it gives incorrect results now

toUTC() converts a datetime to UTC time zone based on the Daylight-Saving Time effectiveness.
When you are converting from CST to UCT, if your date falls when Daylight saving is effective, then it adds +5 to your date else adds +6 to your date.
Example:
Derived column expression: toUTC(toTimestamp(Date_UTC), 'CST')

Related

How to get stripe subscription current_period_end as date

My end goal is to check subscription.cancel_at_period_end for false and store subscription end date as a moment date object.
const subscriptionEndDate = moment(subscription.current_period_end);
This is the result field coming from stripe in test mode.
current_period_end: 1649650039
But even using new Date(subscription.current_period_end) is coming back as 1970-01-20T02:14:10.039Z
Is this not the field that is suppose to show when the next billing date is ?
Any thoughts? What am I missing ?
UPDATE:
I was just doing some testing and figured out if I multiply that value by 1000 it comes out to be 1649650039000 which equates to
Mon 11 April 2022 00:07:19
Is there a reason for this? Is this a safe method moving forward?
UPDATE:
I accepted answer below and am providing momentjs that converts directly to unix timestamp.
const date = moment(new Date()).unix();
Issue
Stripe reports date fields as Unix timestamps. These represent a date/time as the number of seconds since January 1, 1970 (kinda...leap seconds are weird).
The Javascript Date object attempts to convert the number of milliseconds since January 1, 1970 as that is an increment of time that is more relevant to front-end web coding.
Solution
You have already discovered an adequate solution, that is multiply the timestamp by 1000 and thereby convert the value in seconds to a value in milliseconds. This appears to be a common work around 1, 2, 3

I have to convert utc time to ist in excel

I have to convert utc time to ist time in my excel the the time format is 10:00:00 utc this has to converted in IST timing.
Please suggested
There are no inbuilt functions that identify/convert the timezones. We can extend the capabilities of Excel Time() function to solve this use case.
=A1+Time(5,30,0)
For IST, you will have to add 5 hours and 30 minutes. Similarly, you can convert to any timezone by adding/subtracting the time difference.
The three inputs given to the Time() are hours,minutes and seconds.
This function returns the timestamp in a serial number format. Excel will interpret this number and show the timestamp in a readable format.

How to convert a date (Thu 31 Oct 2019 10:08:29) format to Milliseconds (1572516509000) in Load runner (Vugen)

During my scripting in Vugen (Web/HTTP-HTML), I have captured the time in date format (Thu 31 Oct 2019 10:08:29) in parameter file using date-time format (%a %d %b %Y %H:%M:%S). The value I have to pass in the Body section of web_custom_request, it accepts only milliseconds (1572516509000). How we can convert this date format to milliseconds in LR.
Can anyone suggest to me here?
Thanks,
Soumen
Help to understand the use case. Do you need to have the time in milliseconds at the time of submission? At some time in the past for a given date and time? At some point in the future for a given date and time?
The reason why I ask is that there are built in functions for generating a UNIX styled timestamp for the current time. You could potentially plus or minus some number of milliseconds off of this for dates in the past or future depending upon the nature of the request: 86,400,000 milliseconds in a day

Time changes when converting date into ISOString in nodejs

I've got a date string from my database which has this format:
Tue Nov 12 2013 18:14:46 GMT+0100 (CET)
I want to convert it into a ISOString and im currently doing that with:
var iso = new Date(val.text_date).toISOString();
However for some reason the output time is moved 1 hour backwards?
This is the output im getting:
2013-11-12T17:14:46.000Z
How can i avoid this?
Short answer: the time is converted into UTC, and your original time was displayed in UTC+1, hence the one hour difference.
The Date.toISOString() method converts the date into a string in the ISO 8601 format. Note that the returned date in your example ends by a Z: 2013-11-12T17:14:46.000Z. As per the Mozilla documentation and Wikipedia:
If the time is in UTC, add a Z directly after the time without a
space. Z is the zone designator for the zero UTC offset

Convert fraction of day to POSIX times in R [duplicate]

This question already has answers here:
Convert decimal day to HH:MM
(3 answers)
Closed 3 years ago.
I have a dataset that encodes a date-time into two separate variables. Normally, I'd just paste them together inside of an as.POSIXct and carry on. However, the date is provided as a string, and the time of day as a fraction of 24 hours - e.g., 12pm is 0.5, 9:30am is 0.1458333, etc.
It doesn't seem all that tricky to convert the fractional days into clock hours, but I'd prefer to use a pre-existing function if possible. Does something like that exist in base R? A package?
If it's any use, this is an Excel (xlsx) time field imported into R through RODBC.
EDIT
Oddly enough, upon revisiting this problem, the times are now read in as POSIXct. Not sure what to make of that.
The R News 4/1 Help Desk article has a section on reading Excel dates in R.
POSIXct values are simply the number of seconds since midnight GMT 1970-01-01. (So you need to pay attention to your offset from UTC.) You can use the date part and add the number of days times 24*3600 (as.Date(dtval) to your time value * 24*3600. Gabor pointed to the article in R News (which he wrote, thank you, Gabor.)
You didn't give an example of the string. If you are getting your date as a string, then as.Date(strDate) will convert a variable "strDate" to Date class when it is in either "YYYY-MM-DD" or "YYYY/MM/DD" format. Otherwise the formatting codes are on the ?strptime page.
Once you have a POSIXct-classed variable you can just add the number of seconds. This example add 30 minutes to midnight today Feb 1, 2011 (in my time zone which is UTC-5):
> as.POSIXct(as.Date("2011-02-01")) +30*60
[1] "2011-01-31 19:30:00 EST"
And this is your time value added to midnight my time:
> as.POSIXct(as.Date("2011-02-01 00:00", tzone="UTC"))+3600*5 + 3600*24*timeval
[1] "2011-02-01 03:29:59 EST"

Resources