Teradata - Invalid time zone specified while converting time zones - teradata
I am trying to do a join between a date column and the current date in a local timezone using:
SELECT a.* FROM
a
join b on (a.country_id = b.country_id)
and date_column = (Current_date at b.capital_timezone)
b.capital_timezone has values like Europe Central, Europe Eastern,GMT+4, GMT+5:30 etc.,
I get an error saying - 'Invalid time zone specified'
Use the following syntax. Also avoid null values in timezone column.
Current_date at TIME ZONE coalesce(b.CAPITAL_TIMEZONE,'GMT')
According to Teradata docs, GMT+5:30 seems to be an invalid time zone value. Convert it to a valid value.
From the docs:
Strings that do not follow separate DST and standard time zone displacements
'GMT'
'GMT+1'
'GMT+10'
'GMT+11'
'GMT+11:30'
'GMT+12'
'GMT+13'
'GMT+14'
'GMT+2'
'GMT+3'
'GMT+3:30'
'GMT+4'
'GMT+4:30'
'GMT+5'
'GMT+5:30'
'GMT+5:45'
'GMT+6'
'GMT+6:30'
'GMT+7'
'GMT+8'
'GMT+8:45'
'GMT+9'
'GMT+9:30'
'GMT-1'
'GMT-10'
'GMT-11'
'GMT-2'
'GMT-3'
'GMT-4'
'GMT-5'
'GMT-6'
'GMT-6:30'
'GMT-7'
'GMT-8'
Strings that follow different DST and standard time zone displacements
'Africa Egypt'
'Africa Morocco'
'Africa Namibia'
'America Alaska'
'America Aleutian'
'America Argentina'
'America Atlantic'
'America Brazil'
'America Central'
'America Chile'
'America Cuba'
'America Eastern'
'America Mountain'
'America Newfoundland'
'America Pacific'
'America Paraguay'
'America Uruguay'
'Asia Gaza'
'Asia Iran'
'Asia Iraq'
'Asia Irkutsk'
'Asia Israel'
'Asia Jordan'
'Asia Kamchatka'
'Asia Krasnoyarsk'
'Asia Lebanon'
'Asia Magadan'
'Asia Omsk'
'Asia Syria'
'Asia Vladivostok'
'Asia West Bank'
'Asia Yakutsk'
'Asia Yekaterinburg'
'Australia Central'
'Australia Eastern'
'Australia Western'
'Europe Central'
'Europe Eastern'
'Europe Kaliningrad'
'Europe Moscow'
'Europe Samara'
'Europe Western'
'Indian Mauritius'
'Mexico Central'
'Mexico Northwest'
'Mexico Pacific'
'Pacific New Zealand'
'Pacific Samoa'
Related
How to get a timezone string (a la "America/Los_Angeles" or "Pacific Standard Time") from a type Time with TZ info in Golang? [duplicate]
I have an UTC time and a time offset in seconds, and need to return the corresponding Go time value. It is trivial to instantiate the UTC time value by using the time.Unix() function. But to set the Zone, I need to determine the time.Location. How can I find the time.Location when knowing the UTC time and time offset ?
Without an actual entry to lookup in the time zone database, you can't know the true location for the time. If you want to work with just an offset, you can create a fixed location using time.FixedZone edt := time.FixedZone("EDT", -60*60*4) t, _ := time.ParseInLocation("02 Jan 06 15:04", "15 Sep 17 14:55", edt) fmt.Println(t) // 2017-09-15 14:55:00 -0400 EDT You can opt to specify a non-existent zone name, or none at all, as long as the output format you use doesn't require one. minus4 := time.FixedZone("", -60*60*4) t, _ = time.ParseInLocation("02 Jan 06 15:04", "15 Sep 17 14:55", minus4) fmt.Println(t.Format(time.RFC3339)) // 2017-09-15T14:55:00-04:00
How to separate a JSON string into multiple columns in R
I have a column with strings in dictionary format, like this: {'district': 'Ilha do Retiro', 'city': 'RECIFE', 'state': 'PE', 'country': 'BR', 'latitude': -8.062004, 'longitude': -34.908081, 'timezone': 'Etc/GMT+3', 'zipCode': '50830000', 'streetName': 'Avenida Engenheiro Abdias de Carvalho', 'streetNumber': '365'} I want to create one column for each key, filled with the value for each row. I tried using separate with regex: separate(data, address, into = c('district', 'city', 'state', 'country', 'latitude', 'longitude', 'timezone', 'zipCode', 'streetName', 'streetNumber'), "/:.*?/,") However this is not working, and perhaps using separate with regex is not even the best course of action for this. Any suggestions on how to do it?
Since it is effectively JSON (though with single-quotes instead of the requisite double-quotes), we can use jsonlite: txt <- "{'district': 'Ilha do Retiro', 'city': 'RECIFE', 'state': 'PE', 'country': 'BR', 'latitude': -8.062004, 'longitude': -34.908081, 'timezone': 'Etc/GMT+3', 'zipCode': '50830000', 'streetName': 'Avenida Engenheiro Abdias de Carvalho', 'streetNumber': '365'}" as.data.frame(jsonlite::parse_json(gsub("'", '"', txt))) # district city state country latitude longitude timezone zipCode streetName streetNumber # 1 Ilha do Retiro RECIFE PE BR -8.062004 -34.90808 Etc/GMT+3 50830000 Avenida Engenheiro Abdias de Carvalho 365
moment-timezone.js get utc offset for a specific date with timezone
I have users entering a date and a time zone (e.g. "America/Los Angeles") for that date and I'd like to convert that to UTC but to do that I need the utc offset for the time on that date. I can easily convert a date to the offset for the time zone if I already know the UTC date but I need the other way around... The utc offset can change depending on the date due to daylight saving so I need a way to enter a date and a timezone and get back the offset from UTC using that. Knowing the most recent switch from PST to PDT On march 11 at 2AM I tried using var tzOffset = moment.tz("3/11/2018 3:00 AM", "America/Los_Angeles").utcOffset(); document.write('utc offset is : ' + tzOffset + '<br/>') ; but that gives 480 when the correct answer is 420 I can get the correct answer 420 if I use parseZone like so: var tzOffset2 = moment.parseZone("3/11/2018 3:00 AM -07:00").utcOffset(); document.write('utc offset2 is : ' + tzOffset2 + '<br/>') ; but that means I need to already know the -7 offset that I'm trying to find... So how do I find the utcOffset for a specific date/time like "3/11/2018 3:00 AM" and timezone like "America/Los_Angeles"? Thanks
Your input is not in a ISO 8601 or RFC 2822 format recognized by moment(String), so you have to specify the format as second parameter using moment(String, String) (please note that, as docs states: The moment.tz constructor takes all the same arguments as the moment constructor, but uses the last argument as a time zone identifier.) Your code could be like the following: var tzOffset = moment.tz("3/11/2018 3:00 AM", "D/M/YYYY h:mm A", "America/Los_Angeles").utcOffset(); document.write('utc offset is : ' + tzOffset + '<br/>') ; <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.14/moment-timezone-with-data-2012-2022.min.js"></script>
Getting date to appear on x axis of plot.stl method in R
I was wondering if anyone knows of a way to get the dates to appear on the x axis of an stl plot. res<- (stl(ts(data[,variable],frequency=52,start=as.Date(data[1,date]) ),s.window="per",robust=TRUE) ) plot(res) However this is just producing some unicode labels at the bottom of the chart, I have also tried chaning as.Date to as.character however this didn't work. dput of some data: structure(c("2007-01-01", "2007-01-08", "2007-01-15", "2007-01-22", "2007-01-29", "2007-02-05", "2007-02-12", "2007-02-19", "2007-02-26", "2007-03-05", "2007-03-12", "2007-03-19", "2007-03-26", "2007-04-02", "2007-04-09", "2007-04-16", "2007-04-23", "2007-04-30", "2007-05-07", "2007-05-14", "2007-05-21", "2007-05-28", "2007-06-04", "2007-06-11", "2007-06-18", "2007-06-25", "2007-07-02", "2007-07-09", "2007-07-16", "2007-07-23", "2007-07-30", "2007-08-06", "2007-08-13", "2007-08-20", "2007-08-27", "2007-09-03", "2007-09-10", "2007-09-17", "2007-09-24", "2007-10-01", "2007-10-08", "2007-10-15", "2007-10-22", "2007-10-29", "2007-11-05", "2007-11-12", "2007-11-19", "2007-11-26", "2007-12-03", "2007-12-10", "2007-12-17", "2007-12-24", "2007-12-31", "2008-01-07", "2008-01-14", "2008-01-21", "2008-01-28", "2008-02-04", "2008-02-11", "2008-02-18", "2008-02-25", "2008-03-03", "2008-03-10", "2008-03-17", "2008-03-24", "2008-03-31", "2008-04-07", "2008-04-14", "2008-04-21", "2008-04-28", "2008-05-05", "2008-05-12", "2008-05-19", "2008-05-26", "2008-06-02", "2008-06-09", "2008-06-16", "2008-06-23", "2008-06-30", "2008-07-07", "2008-07-14", "2008-07-21", "2008-07-28", "2008-08-04", "2008-08-11", "2008-08-18", "2008-08-25", "2008-09-01", "2008-09-08", "2008-09-15", "2008-09-22", "2008-09-29", "2008-10-06", "2008-10-13", "2008-10-20", "2008-10-27", "2008-11-03", "2008-11-10", "2008-11-17", "2008-11-24", "2008-12-01", "2008-12-08", "2008-12-15", "2008-12-22", "2008-12-29", "2009-01-05", "2009-01-12", "2009-01-19", "2009-01-26", "2009-02-02", "2009-02-09", "2009-02-16", "2009-02-23", "2009-03-02", "2009-03-09", "2009-03-16", "2009-03-23", "2009-03-30", "2009-04-06", "2009-04-13", "2009-04-20", "2009-04-27", "2009-05-04", "2009-05-11", "2009-05-18", "2009-05-25", "2009-06-01", "2009-06-08", "2009-06-15", "2009-06-22", "2009-06-29", "2009-07-06", "2009-07-13", "2009-07-20", "2009-07-27", "2009-08-03", "2009-08-10", "2009-08-17", "2009-08-24", "2009-08-31", "2009-09-07", "2009-09-14", "2009-09-21", "2009-09-28", "2009-10-05", "2009-10-12", "2009-10-19", "2009-10-26", "2009-11-02", "2009-11-09", "2009-11-16", "2009-11-23", "2009-11-30", "2009-12-07", "2009-12-14", "2009-12-21", "2009-12-28", "2010-01-04", "2010-01-11", "2010-01-18", "2010-01-25", "2010-02-01", "2010-02-08", "2010-02-15", "2010-02-22", "2010-03-01", "2010-03-08", "2010-03-15", "2010-03-22", "2010-03-29", "2010-04-05", "2010-04-12", "2010-04-19", "2010-04-26", "2010-05-03", "2010-05-10", "2010-05-17", "2010-05-24", "2010-05-31", "2010-06-07", "2010-06-14", "2010-06-21", "2010-06-28", "2010-07-05", "2010-07-12", "2010-07-19", "2010-07-26", "2010-08-02", "2010-08-09", "2010-08-16", "2010-08-23", "2010-08-30", "2010-09-06", "2010-09-13", "2010-09-20", "2010-09-27", "2010-10-04", "2010-10-11", "2010-10-18", "2010-10-25", "2010-11-01", "2010-11-08", "2010-11-15", "2010-11-22", "2010-11-29", "2010-12-06", "2010-12-13", "2010-12-20", "2010-12-27", "2011-01-03", "2011-01-10", "2011-01-17", "2011-01-24", "2011-01-31", "2011-02-07", "2011-02-14", "2011-02-21", "2011-02-28", "2011-03-07", "2011-03-14", "2011-03-21", "2011-03-28", "2011-04-04", "2011-04-11", "2011-04-18", "2011-04-25", "2011-05-02", "2011-05-09", "2011-05-16", "2011-05-23", "2011-05-30", "2011-06-06", "2011-06-13", "2011-06-20", "2011-06-27", "2011-07-04", "2011-07-11", "2011-07-18", "2011-07-25", "2011-08-01", "2011-08-08", "2011-08-15", "2011-08-22", "2011-08-29", "2011-09-05", "2011-09-12", "2011-09-19", "2011-09-26", "2011-10-03", "2011-10-10", "2011-10-17", "2011-10-24", "2011-10-31", "2011-11-07", "2011-11-14", "2011-11-21", "2011-11-28", "2011-12-05", "2011-12-12", "2011-12-19", "2011-12-26", "442573", "452832", "452785", "459228", "479509", "477631", "465619", "462001", "485567", "462381", "456059", "457401", "474094", "468766", "456945", "539126", "545640", "511801", "486619", "484430", "481428", "470622", "479677", "486755", "477617", "483656", "497479", "493436", "480080", "481527", "516029", "532349", "503939", "472171", "461550", "504532", "489715", "480032", "488376", "470772", "467395", "488155", "455712", "474456", "471237", "482943", "459320", "456956", "465056", "461930", "441201", "451255", "464508", "449199", "455411", "476323", "521761", "513416", "521070", "497596", "485461", "485593", "461148", "429938", "441207", "459484", "462099", "469285", "454395", "456729", "469251", "517727", "526719", "477985", "484538", "469766", "472399", "481162", "479039", "481071", "485068", "462108", "459079", "452410", "488574", "502166", "504323", "514529", "524206", "504315", "462935", "461899", "461551", "455491", "456857", "443314", "454586", "458943", "450555", "454311", "442808", "440126", "414876", "415787", "413352", "423864", "448319", "415440", "431948", "433313", "448509", "436400", "454154", "454183", "447735", "452220", "451433", "472808", "446767", "426595", "463693", "435673", "452704", "456828", "465069", "448685", "457353", "443859", "463972", "480139", "493342", "500982", "529602", "527365", "512005", "484585", "455007", "470006", "477522", "443956", "459038", "488877", "466669", "476242", "470862", "457298", "466438", "454062", "460216", "466645", "445113", "457255", "451553", "451504", "447991", "435100", "416140", "481390", "489041", "496984", "486245", "478191", "455201", "448085", "459097", "480859", "490248", "462523", "489755", "468391", "460229", "481276", "472845", "481099", "476435", "487314", "475043", "476847", "461928", "483488", "479379", "456732", "461538", "480773", "471101", "459898", "482129", "464356", "459420", "457850", "456764", "438152", "467928", "464732", "458767", "470256", "449488", "433263", "428548", "435099", "429163", "424251", "434723", "425841", "399498", "418791", "405051", "385037", "425144", "418296", "397644", "414283", "431907", "429117", "424862", "439664", "432791", "443588", "434985", "442418", "445760", "449290", "451412", "456247", "444372", "441390", "458192", "456435", "450670", "447609", "439083", "464513", "462784", "439423", "450857", "442374", "447753", "440207", "435254", "430841", "437233", "426523", "430127", "431305", "470244", "508878", "511064", "504182", "462076", "452218", "426535", "436892", "459008", "441449", "438783", "427497", "432275", "436745", "423068", "429574", "416074"), .Dim = c(261L, 2L))
The problem is with how you have created the time series object. ?ts will give you start : the time of the first observation. Either a single number or a vector of two integers, which specify a natural time unit and a (1-based) number of samples into the time unit. Since your data starts at 2007-01-01 and is a weekly data, you have to specify c(2007,1), Note that the "1" here denotes that data start from the 1st week of 2007, as the data is weekly. Here the frequency should be set to 52 because, after 52 cycles/weeks a year will change from 2007 to 2008. This should work res<- (stl(ts(data[,2],frequency=52,start=c(2007,1 )),s.window="per",robust=TRUE) )
Get value by date
I have a data frame df: PRICE 2004-03-19 36.250000 2004-03-20 36.237500 2004-03-21 36.225000 2004-03-22 36.212500 etc... The index is of type: DatetimeIndex(['2004-03-19', '2004-03-20', '2004-03-21', ...], dtype='datetime64[ns]', length=1691, freq='D') I want to retrieve the PRICE at a certain day using df[datetime.date(2004,3,19)]. This is what pandas does: KeyError: datetime.date(2004, 3, 19) The following works, but that can't be the way it is supposed to work: df[df.index.isin(pd.DatetimeIndex([datetime.date(2004,3,19)]))].PRICE.values[0]
The problem here is that the comparison is being performed for an exact match, as none of the times are 00:00:00 then no matches occur. You can use loc with DatetimeIndex: print df.loc[pd.DatetimeIndex(['2004-3-19'])] PRICE 2004-03-19 36.25 Or you can use loc, convert string 2004-3-19 to_datetime and get date of DatetimeIndex: print df.loc[pd.to_datetime('2004-3-19').date()] PRICE 36.25 Name: 2004-03-19 00:00:00, dtype: float64 If you need value of PRICE: print df.loc[pd.DatetimeIndex(['2004-3-19']), 'PRICE'] 2004-03-19 36.25 Name: PRICE, dtype: float64 print df.loc[pd.DatetimeIndex(['2004-3-19']), 'PRICE'].values[0] 36.25 print df.loc[pd.to_datetime('2004-3-19').date(), 'PRICE'] 36.25 But if add time to datetime, DatetimeIndex match: print df.loc[pd.to_datetime('2004-3-19 00:00:00')] PRICE 36.25 Name: 2004-03-19 00:00:00, dtype: float64 print df.loc[pd.to_datetime('2004-3-19 00:00:00'), 'PRICE'] 36.25
Your index appears to be timestamps, whereas you are trying to equate them to datetime.date objects. Rather than trying to retrieve the price via df[datetime.date(2004,3,19)], I would simply recommend df['2004-3-19']. If you are intent on using datetime.date values, you should first convert the index. df.index = [d.date() for d in df.index]