Where do Oracle Functions like TZ_Offset and FROM_TZ get their data from? - oracle

I'm working on optimizing some functions in which I need to convert many timestamps to UTC. My need is to create a table with the columns as follows:
YEAR | TZ_NAME | Start of Daylight Savings | End of Daylight Savings
I can convert the timestamps easily using the from_tz function in oracle, however running this per timestamp isn't an option. Does anyone know how the oracle function works? I can't find any documentation that details where oracle keeps these daylight savings rules.
Any suggestions?
Thank you!

The time zone related information is stored in a file, as per: https://docs.oracle.com/cd/B19306_01/server.102/b14225/ch4datetime.htm#i1006667
The Oracle time zone files contain the valid time zone names. The
following information is also included for each time zone:
•Offset from Coordinated Universal Time (UTC)
•Transition times for Daylight Saving Time
•Abbreviations for standard time and Daylight Saving Time

Related

How to migrate existing MariaDB timestamp columns from local Timezone to UTC

Currently my laravel config time zone is set to '+6:00' and MariaDB database time zone is set to SYSTEM, which is +6:00 as well. Now that I need to accommodate users from different time zones, I need to migrate all timestamp values to UTC to avoid any unintended time-related issues.
In MariaDB documentation it is stated that: https://mariadb.com/kb/en/timestamp/#time-zones
If a column uses the TIMESTAMP data type, then any inserted values are
converted from the session's time zone to Coordinated Universal Time
(UTC) when stored, and converted back to the session's time zone when
retrieved.
Now, this is where I am getting confused. What I understand from the above statement that I do not require to change anything in the database as timestamps are always stored in UTC no matter what is my session time zone is at the time of saving the data. Therefore, later on if I update my time zone to UTC in Laravel config, I should get the corresponding UTC value. But after changing the Time zone to UTC in Laravel config I am still getting the time in +6:00 format from eloquent model.
I think I am missing something here and would really appreciate any suggestion regarding this. Thanks in advance.

MongoDB date import via Talend from Oracle is out by 1 day

I am actually using the mongDB API via a tLibraryLoad component, as I find this easier to build complex multi-level documents using tJavaRow and tJava components, than using the MongoDB palette components.
I am reading in data from Oracle which are date values with a zero time stamp component: For example:
29-JUN-08 00.00.00
The import works via Talend, however the records in mongo shell appear to be the previous day. You can see the record is inserted as the 28-JUN-2008.
Extract from JSON document in mongoDB:
"status_date" : ISODate("2008-06-28T23:00:00Z")
It is almost as if mongoDB (or Talend?) sees a midnight date as the end of the previous day, rather than the start of the 29th June 2008.
In my Talend schema I have specified the Oracle columns as Date types with a DB Type of Date also.
Any advice appreciated.
---UPDATE 1------
As only some dates are affected, it seems this is a DST adjustment in mongoDB to adjust perhaps the display to my local timezone, as the dates which are impacted are in the back half of the year in daylight saving time.
Is it adjusting the date due to the location of the mongo shell?
It is adjusting the date due to the location of the mongo server so all people using the mongo shell would get the same answers to date queries?
Would different people running different mongo queries on dates get different results based on their location, their DST kick in dates...i.e. you could imagine dates from the 1st November 2015, being counted as contributing to October 31st figures (at 23:00)....
i
I feel your pain - this is derived from MongoDB itself.
At issue is that MongoDB stores dates in UTC format by default.
https://docs.mongodb.org/manual/tutorial/model-time-data/
You can use Mongo's suggestion above but in this case you are storing just the date and not the time. I've used two solutions:
Don't bother storing dates as DATEs. Convert all your dates to %Y%m%d format and store them as integers. You can easily compare dates using $gt and $lte just using integers - just be sure to bring in your date using the same format and convert them back in your program later.
... or ...
Since in your case your date seems to be off by an hour, add an hour to it before you make your insert. It all depends on how long the timezone offset is to your local machine.
On linux you can see what the utc value is using:
date -u
I suppose you could change your local timezone on your machine to be UTC time and see what happens.
Personally, I've never had an issue with using the first approach. It's fast and ensures that I have what I want in there.
I think it is because of the timezone of your server. Try to remove the timezone from your date object and then insert it to the mongodb.
With moment.js you can create date without the timezone in such way:
var date = moment.utc("29-JUN-08 00.00.00", 'DD-MM-YYYY h.mm.s').format()

Generating date_time_zonespec.csv for boost::date_time from IANA's time zone database?

The time zone database (date_time_zonespec.csv or boost_1_55_0/libs/date_time/data/date_time_zonespec.csv) of boost::date_time library seems not to be up to date. Is there a way to generate it from latest version of IANA time zone database?
This should be the answer found in boost::locale reference:
Why don't you use Boost.DateTime time zone support?
Boost.DateTime's time zone support is broken. Time zones can not be
represented with a simple table of rules where daylight saving depend
only on certain n'th day of week in month. The daylight savings time
may vary by year, political issues and many other things.
There is also the new C++20 date functions, added to the chrono lib. It can use your system's TZ database, at least on Linux/Mac, or you can have the library automatically download the latest TZ to a folder instead. You can try it out here: https://github.com/HowardHinnant/date

Will changing the system timezone convert all the time/date data into that timezone?

I have a record with purchase date of 1/1/2015 10:30 AM and my system timezone is UTC.
If I change the database timezone to Eastern Time. Would the purchase date for the existing record be automatically converted to Eastern Time? For example from 1/1/2015 10:30AM to 1/1/2015 5:30PAM.
Is this a feature in Oracle?
Also, is there a way to figure out what timezone the pruchase date was recorded in?
Since your column's data type is TIMESTAMP, Oracle has no idea what time zone that timestamp is in. The data won't change if you change the time zone on either the client or the server. Similarly, there is no way to determine whether a particular value was intended to represent EST or MST or UTC. Obviously, if you know that all your data is recorded in UTC, you could write an update statement that converted the data to a different time zone.
If you care about the time zone and want to do time zone conversions, you'd really want to store the time zone along with the date in a TIMESTAMP WITH [LOCAL] TIME ZONE column. That makes it much easier to convert the data from one time zone to another. If you use a TIMESTAMP WITH LOCAL TIME ZONE, Oracle will automatically convert the data to the session's preferred time zone which allows different users to see the same data in their time zone without manipulating the data in the database.

Oracle date

How is Oracle date implemented? Is it stored as milliseconds or something like that?
An Oracle DATE stores the date and time to the second. An Oracle TIMESTAMP stores the date and time to up to 9 digits of subsecond precision, depending on the available hardware.
Both are implemented by storing the various components of the date and the time in a packed binary format. From the Oracle Concepts Guide section on dates
Oracle uses its own internal format to
store dates. Date data is stored in
fixed-length fields of seven bytes
each, corresponding to century, year,
month, day, hour, minute, and second.
You can use the DUMP() function to see the internal representation of any particular date (or any other value for that matter), but that's probably more than you need (or want) to know.
Apparently, not in form of millisecs.
Which actually makes sense, since they do not have any running operations on current date/time:
http://www.ixora.com.au/notes/date_representation.htm
http://infolab.stanford.edu/~ullman/fcdb/oracle/or-time.html
http://www.akadia.com/services/ora_date_time.html
No. DATE is a timestamp value with seconds precision. You need TIMESTAMP(3) to store milliseconds.

Resources