Anomaly inserting current_timestamp() into MariaDB table - go

I'm writing a program using Golang (1.17.8), storing information in a MariaDB (10.6.5) database. I often need to store a created_at field inserted as current_timestamp() which is pretty common.
My system time is UTC +1.00 (BST) and I'm working with Windows 10 (21H1)
MariaDB is set to use system time and from the command line both SELECT NOW() and SELECT CURRENT_TIMESTAMP() output exactly that.
Logging the output of the Golang function time.Now() also gives system time.
If I insert time.Now() from my program into my MariaDB table it is inserted as UTC
Perhaps a simple reason exists for this but I do not know why. I have not ever used a different timezone and as mentioned, MariaDB reports it is using system time anyhow.
How can I change this please ?

As the documentation states, this is normal behavior in the absence of a timezone. Which time zone would you wish to use in your output?
Is your server in the UTC timezone by any chance?

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.

Oracle (XE) & SQL-Developer: how to find out the time/date/timestamp format being used?

I recently wrote a tool that extracts certain data from our DBs. It runs as PL/SQL script running in SQLDeveloper (either in a worksheet or as extension plugin) and produces its output to the SQLDeveloper log-window.
This worked all fine on my system, but now I encountered an issue when users are on systems with a different language or more specific with different default time/date/timestamp formats than on the machine on which I had been developing and testing this.
Now - I am not sure: is the format of dates, times and timestamps controlled by the DB or by SLQ-Developer? In my understanding these PL/SQL scripts are sent to the DB for execution and their output is sent back to SQL-Developer. That would mean for me, that the format of the output depends solely on the DB (or the system on which the DB executes). Or are the NLS setting of the client (SQL-Developer) somehow involved here?
To make my tool auto-adjust to these settings I will need to be able to query these formats - either from the DB in use (Oracle 12.2 or Oracle XE 18/19 in our case) or from SQLDeveloper.
Assuming, it's the DB: Is there a table that contains the default format strings that are being used for select results?
Note: The point is NOT how to format dates etc. as strings, but the other way round:
I get the the query results as strings in the log-window. These contain dates and timestamps. I now need a hint from the DB-system to figure out how to interpret these. E.g. when I get a date such as '10-11-12', is this meant to be Nov. 10th, 2012 or is meant to be Nov. 12th, 2010?
Hope I could make myself clear...

Time zone used for Oracle Date field

TL;DR - am I correct in thinking there is no way to determine the timezone used for a given record of a Date field when the server's time zone was changed at some point in the past?
A factory control system was designed to use UTC server (not Oracle) time so all Date columns were UTC. At some point in the past they changed the server time to local. Now years later, they would like the apps to display the correct date. Without knowing the date the change occurred, is there a way to SELECT so all Date records would be correct? I think I can either make the "modern" records correct or the pre-change records correct but not both unless I know when that happened. Since it was a Windows OS change, I don't think even the alert log would help assuming they haven't trimmed it at some point, but it's not easy to get any info or server access from them anyway. It had been 10g and is now 12c.
Correct. Oracle's DATE datatype is timezone agnostic. If you want to store timezone info in the database, use TIMESTAMP WITH TIMEZONE datatype.

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()

Oracle overwrites my Date?

I got a problem with Oracle Dates. It seems that predefined Dates in an Java Application are different after inserting into an OracleDB.
Insert via JPA entity:
entity.setDateOfCreation(new Date(System.currentTimeInMillis()));
// 1350565985000
After commit and retrieve:
entity.getDateOfCreation() // 1350565985047
Why is this different?
I assumed Oracle would just insert my specific Date Object with these exact Milliseconds into the Database. But obviously it doesn't. Because of the minimal delay it seems to "overwrite" the given Date with its own Date in milliseconds (and despite I do NOT use #GeneratedValue).
Does the table you working with have a trigger which populates that column? I would hope it does. I have experienced lots of problems in the last with time differences between the app server and the database. It is much better to have a single of time which ensures consistent timings across the state.

Resources