When I load the datetime column into snowflake I see 10 and 11-hour differences - datetime

I'm trying to combine two columns with date and time data in the ETL tool and load them into snowflake. When I load the data as datetime, there are 10 and 11 hour differences. At the same time, I share with you the current hours of Snowflake and my local.
select current_timestamp >> '2022-11-15 23:46:47.318 -0800'
My current hour is now >> '2022-11-16 10:46:47.318'
The photo below will help to understand the problem more closely. STAGE_DATE Merged version of VBRK_FKDAT and VBRK_ERZET. I want to see this date. I combine VBRK_FKDAT and VBRK_ERZET from Data Services and after I get 10 hours I send snowflake. This stands for INVOICEDATE. When I take the difference of INVOICEDATE and STAGE_DATE I get HOURDIFF. Randomly there are 10 and 11 hours difference. I'm trying to understand the problem.
Thank you for your interest.

What you've explained is most probably related to the current setting for the TIMEZONE:
Default: America/Los_Angeles
The timestamps are stored internally in UTC but are displayed for the user based on the TIMESTAMP parameter value for session/user/account.
For more information have a look here.

Related

Ms-Access convert datetime to seconds since epoch [duplicate]

I'm trying to write a query for an MS Access 2007 connection to a MySQL database through ODBC. Everything's working fine, and the query does what I want it to do. The part that I'm hung up on is that I'm stuck asking the user for unix epoch time, instead of a regular date.
I looked up a bunch of references for MS Access, and while there are a number of date conversion functions I can use in the SQL call, I can't find any that I can use to convert from a normal date -> unix epoch date.
What I would like, and I assume this works, is to ask the user for the date in a much kinder fashion (a human readable date), and then convert it into unix epoch date. Now that I think about it, I guess my other option is to convert the unix epoch dates in the database after drawing them out with the SQL query, but I'd rather convert the user's input if at all possible as there is less of that input so I wouldn't have to do as much work.
SELECT TOP 5 Count( * ) AS [Number of visits by language], login.lang AS [Language]
FROM login, reservations, reservation_users
WHERE (reservations.start_date Between [Starting unix epoch time] And [Ending unix epoch time]) And reservations.is_blackout=0 And reservation_users.memberid=login.memberid And reservation_users.resid=reservations.resid And reservation_users.invited=0
GROUP BY login.lang
ORDER BY Count( * ) DESC;
Don't know if this is going to work (don't have Access to confirm), but try the suggestion from here:
http://weblogs.sqlteam.com/jeffs/archive/2007/04/13/format-date-sql-server.aspx
which is to use:
DATEDIFF(second, '1 Jan 1970', tbl.LastChangeDate)
This is from some of the comments.
EDIT: See the comment from Remou.
Using MS 2010 I found this works: DateAdd("s",([epoch timestamp]-21600),#1/1/1970#)
http://www.pcreview.co.uk/forums/convert-epoch-date-t2324318.html

SQLite: How to convert a bigint field to date or timestamp?

I've received a SQLite file with .db extension.
Opening it, I have a column with serial numbers: i.e. 1600414704594 (that should correspond to 2020-10-09 and whatsover time)
The db comes from outside and I don't know how that date field has been built.
Could you suggest me a query to get a valid date/time from that db column ?
I've tried reading this post but none of the given solution returned me a valid (and actual) date, please help me.
It looks like an Unix time in milliseconds. SQLite's unixepoch modifier expects it in seconds. The conversion is fairly easy :
SELECT DATETIME(1600414704594 / 1000, 'unixepoch')
2020-09-18 07:38:24

Oracle 11g SQL loader, time format issue

I am trying to load a .csv file using SQL loader. I get this error message on a column that should store time column:
column TIME.ORA-01843: not a valid month
In my .csv file time has the format HH:MM:SS but I can't understand why Oracle does not recognise it.
Using the command select * from nls_session_parameters; I see that the default time format is HH24.MI.SSXFF. I tried to change the time separator in my csv file but I got the same error result.
I have a very simple control file, that looks like below.
LOAD DATA
INFILE Cycling_Accidents0512.csv
INTO TABLE CYCLING_ACCIDENTS
FIELDS TERMINATED BY ','
(ID,
ACC_ID,
OSGB_EASTING,
OSGB_NORTHING,
WGS_LONG,
WGS_LAT,
POLICE_FORCE,
ACC_SEVERITY,
NUM_VEI,
NUM_CAS,
ACC_DATE,
DAY_WEEK,
TIME,
LOC_AUTH_DIS,
LOC_AUTH_HIGH,
FST_ROAD_CLASS,
FST_ROAD_NUMBER,
ROAD_TYPE,
SPEED_LIMIT,
JUNCT_DETAIL,
JUNCT_CONTROL,
SND_ROAD_CLASS,
SND_ROAD_NUM,
PED_HUM,
PED_PHY,
LIGHT_COND,
WEATH_COND,
ROAD_SUR_COND,
SPEC_COND,
CARR_HAZARDS,
URB_RUR,
POLICE_ATT,
LSOA_ACC_LOC,
VEI_TYPE)
If someone of you can help me to modify the control file in order to make the time format acceptable to Oracle, that would be appreciated. I tried to look up on other web resources but I haven't found anything that could help.
Thanks!
You mentioned querying the session NLS parameters, but the value you showed appears to be NLS_TIME_FORMAT, which is only used internally.
Oracle doesn't have a time-only type, so your field is presumably actually a DATE type (or possibly TIMESTAMP). The values in the column will have a date part, even if you ignore it.
SQL*Loader will use NLS_DATE_FORMAT to interpret the data file value for a DATE field. If that is DD/MM/YYYY then it would liberally interpret a value like 22:41:17 as the 22nd day of the 41st month - hence your error - in the year 17.
You can specify the date format model in the control file:
TIME DATE 'HH24:MI:SS',
The value in the table would have that time, on the first day of the current month.
The SQL*Loader documentation does refer to a TIME data type which I have never seen used, and I can't find any references to it anywhere, including MOS. A quick bit of experimentation hasn't helped. If I make the control file entry:
TIME TIME,
... then the record is rejected with ORA-00933: SQL command not properly ended. The log file also shows the data type as DATETIME HH24.MI.SSXFF, which looks related to the NLS_TIME_FORMAT value. I haven't found a way to make it accept that. If I change the column definition from DATE to TIMESTAMP then I get a different error, ORA-00904: "TO_TIME": invalid identifier, which is even stranger. It almost looks like these data types are defined in SQL*Loader for future use. (This discussion suggests they thought about adding TIME as a database type in 10g, but obviously can't verify that. And this is in the SQL*Loader reference at least back to 9i).

How do I pull values between two datetimes at specific interval in MySQL?

I have an application that writes temperature values to a MySQL table every second, It consists of the temperature and a datetime field.
I need to pull these values out of the table at specific intervals, every second, minute, hour etc.
So for example I will need to pull out values between 2 datetime fields and show the temperature at the hour for each of them.
One option I've considered is to create a temporary table that holds a list of the time intervals generated using MySQL INTERVAL and then joining that against the main table.
I'm just wondering if there's some time and date functions in MySQL that I'm overlooking that would make this easier?
Thanks.
You could use between for your date, and then a conditional WHERE clause using time() that looks at the structure of the timestamp. If it has 00:00 (for instance, 16:00:00) within it, take it, if not, leave it.
Example (untested):
SELECT temp, date
FROM temperatures
WHERE (date BETWEEN '2009/01/03 12:00:00' AND '2009/01/04 12:00:00')
AND (time(date) LIKE '%:00:00')
ORDER BY date ASC
LIMIT 10

Cast Date in Informix

I have never used Informix before and I'm trying to write a query that will return records over the last 365 days.
Here is the query I have been trying to use:
Select * from Visit where vis_mod_dt between today-365 and today;
That returns no records even though I know that there is data for the last 365 days. I am guessing that the vis_mod_dt in not a true date column, although it displays as '12/31/1899' I have tried to cast this column using:
select * from visit where date(vis_mod_dt) between today-365 and today;
This still returns no data.
Any ideas?
Informix DATE format
Be aware that the date 1899-12-31 corresponds to the internal date representation of zero (0). That is, internally, Informix stores DATE values in a 4-byte integer, and counts the number of days since 1899-12-31, so Day 1 was 1900-01-01 (and since it knows that 1900 was not a leap year, Day 60 was 1900-03-01).
That fact makes me worry about what is in your table. However, if the data in your table cannot be converted to a DATE upon request, normally you would get an error.
What is your table schema?
It would be sensible for you to establish the schema either using DB-Access and the Info/Tables option, or use DB-Schema:
dbschema -d dbase -t visit
The DB-Schema output is more suitable for adding to your question.
The query expressions using 'TODAY-365' and 'TODAY' should work fine - if there is data to select.
DBDATE environment variable
There is an environment variable, DBDATE, that you may need to set to get things to work - to convert from a string representation to dates. Since you are probably based in the UK (from your icon), then you may want and need to set the value of DBDATE to:
export DBDATE=DMY4/
This says that dates consist of the day, the month, a 4-digit year and the '/' is used as the preferred separator. You won't be surprised to learn that the presumed default value is usually 'MDY4/', for US format; I use 'Y4MD-' habitually, so I see DATE value the same as DATETIME YEAR TO DAY, which is the ISO 8601:2004 notation for a date. (It has many benefits: it is unambiguous, and naive sorting algorithms sort such dates into date order.) There's actually a lot of mechanism in the background in IDS (IBM Informix Dynamic Server - which, I assume, is the DBMS that you are using; there are some alternatives that are also Informix DBMS) such that strings with 2-digit dates will usually be converted correctly (but they are ambiguous and undesirable), and separators other than '/' will be recognized on input, but the slash will be used on 'output' (when converting DATE to string).
Information needed to improve the answer to this question - 1st Edition.
If what is here does not help, then I recommend editing your question to include:
The table schema.
A few (2-4) rows of data that you think should be selected but aren't.
Platform and version information. It can help to have the version down to the level of detail of IDS 11.50.FC4W1; occasionally it matters. Most usually, the first three digits are what affect things, of course.
If your table is big (many columns), try to select the key columns (vis_mod_dt is by far the most important one). Ideally, you won't need any scroll bars in the display.
Make sure you don't include any sensitive information.
Information needed to improve the answer to this question - 2nd Edition
I will help you if you pay attention to the questions I ask you. I cannot help you if you do not pay attention to the questions I ask. And please edit your question rather than adding information as an 'answer'.
What is the table schema? What is the output from:
SELECT t.tabid, t.tabname, c.colno, c.colname, c.coltype, c.collength
FROM "informix".systables AS t, "informix".syscolumns AS c
WHERE t.tabid = c.tabid
AND t.tabname = "visit"
ORDER BY t.tabid, c.colno;
What do you get from:
SELECT TODAY, TODAY-365 FROM "informix".systables WHERE tabid = 1;
Do you have the environment variable DBDATE set? If so, what is its value?
Do you have the environment variables CLIENT_LOCALE or DB_LOCALE set? If so, what are their values?
Which version of Informix are you using?
Which platform are you using it on?
Which language or tool are you using to run the query.
Note: if you cannot copy'n'paste the queries above, then you probably do not need to include the quoted '"informix".' attributes on the system catalog; however, as written, the queries will work on any extant Informix database - OnLine 5.x, SE 5.x or 7.x, IDS 7.x, XPS 8.x, IDS 9.x or 10.x or 11.x - and any mode of database (unlogged, logged, MODE ANSI). I'd use the JOIN notation except that some of the older versions don't support it - though you have to be on very old versions for that to be a problem.
This is a little confusing, because when I run the following, I get data:
select count(*) from visit where vis_mod_dt between "10/01/2008" and "10/01/2009"
how about unloading the table to ascii file, examine the unloaded vis_mod_dt values to see if they conform to DBDATE=MDY4 (mmddyyyy) format?.. if they do, ALTER vis_mod_dt to TYPE DATE if it's not a DATE column, then LOAD the unloaded table back in.
the: "BETWEEN today-365 AND today" part of your SELECT statement works for me in my apps.

Resources