Ruby convert Mysql timestamp to Mysql datetime - mysql

I am trying to import data from a DB to another. The source DB has TIMESTAMP (mysql) the destination has DATETIME (mysql). I am trying something like that:
start_at = DateTime.at(row['QA_CONF_START_STAMP']) #start_at
But it is not working

I'm not sure if conversion is expressly required in this case, as the two values should be equivalent.
Since you're not retrieving the original data using a model, it's coming through as a raw string. The easiest way to interpret that is:
DateTime.parse(row['QA_CONF_START_STAMP'])

Related

informatica Datetime conversion to SQL server Timstamp

I have a requirement where I have to load Informatica SESSSTARTTIME(datetime) to SQL server timestamp. When I am trying to connect datetime to timestamp I am getting error incompatible data type. 
Any suggestions how this can be achieved? 
Thanks
I had a similar issue in the past, where the date column was not getting loaded because of the difference in precision of date/time used by Informatica and SQL server. You can try this workaround: Change the data type in the target definition (not in SQL Server table, only in Informatica Target definition) to String, then Informatica will pass the date/time value in quotes when firing the insert query, which SQL server can convert to date/time automatically.
in the mapping try to create output port in expression as sessionstarttime (which is a inbuilt variable) and pass it to target
hope this will help to get desire output
in session there is config tab where you can change the format for date and time
MS SQL Server timestamp datatype has nothing to do with time. It's an autogenerated number and you cannot load it.
https://msdn.microsoft.com/en-us/library/ms182776(v=SQL.90).aspx
quote:
"Is a data type that exposes automatically generated, unique binary numbers within a database. timestamp is generally used as a mechanism for version-stamping table rows. The storage size is 8 bytes. The timestamp data type is just an incrementing number and does not preserve a date or a time. To record a date or time, use a datetime data type."

How to store "1/01/1900 3:54:32 a.m." in MySQL?

I'm saving data from a CSV file into a MySQL database. I'm using Laravel and trying to decide what is the best way to store such data. See: http://laravel.com/docs/4.2/schema#adding-columns. Do I use timestamp? Would I lose anything if I just stored it as a string?
Use datetime
The advantage of datetime over string is that it will be stored more efficiently and you will be able to query this data with more tools
Read more in the docs

Database connection using dplyr with date field in database

Is there some magic to using dplyr to access a database when it has a date field?
A dplyr tbl_df converts mysql datetime fields to chr. That wouldn't be so bad if I could as.Date() them back. But if I do that before collect()'ing the table, I get an error that as.Date() is an invalid sql function. I can sort-of workaround this by calling collect(), but then I'm copying all of the data out of the database, which is what I was trying to avoid. In addition, once I've collect()'ed, its a data.frame, so if I want to join it with another tbl I have to set copy=TRUE and copy that one into memory as well.

Finding specific value in MySQL database

This may sound strange but is it possible to construct a SQL statement that search all the tables in a database for a specific value? I'm testing another person's Drupal(V.7) code and that code uses taxonomy_term_save function to import data in CSV format. I like to find the table where these data are stored. I don't know the field name either. Is it possible? I use MySQL.
SELECT * FROM databasenameHERE WHERE tablenameHERE = 'keyYouAreSearchingForHere'";
That is for MySql

Dealing with different datetime formats in the DB?

I'm writing a Ruby program using Sequel which is running on the legacy database. There is an issue dealing with different date time formats.
DB has a table which has a column start_date. In Sequel's migration script I set it to DateTime which is a timestamp type in SQLite, however, the legacy data has a different time format:
Some are using an ISO8601, like 2013-09-01T08:28:00+10:00.
Some are using a different one, which I don't know if it has a name, like 2013-09-01 08:28:00.000000+1000.
The problem is, when I run a query against the table and try to filter by start_date, the difference between two date time formats will cause incorrect results.
The query I'm using is:
current = Time.now
MyModel.where { start_date < current }
Sequel will convert it into SQL like this:
SELECT * FROM `my_model` WHERE `start_date` < '2013-09-01 08:28:00.000000'
From my local testing, Sequel looks like it's comparing the date as a string, so 2013-09-01 08:28:00.000000+1000 is less than 2013-09-01T01:28:00+10:00. Because whitespace is less than T this is not what I want.
I could use an iso8601 time like:
current_iso8601 = Time.now.iso8601
MyModel.where { start_date < current_iso8601 }
But it won't solve the problem because the database has two different datetime formats.
My questions are:
Does Ruby/Sequel support querying the database by Date/Time not as a string?
Does it work for different date time formats?
SQLite is just for local testing, in production it will be MySQL. So, the solution should be using general Sequel methods as a adaptor and should not have any database specific methods.
NOTE: the program is not a Rails application.
Thank you very much!
SQLite does not have date/time types (see http://sqlite.org/datatype3.html). It stores datetime values as strings.
The best solution is to use the same database in development/testing that you use in production. If you don't want to do that, you need to convert all the SQLite datetime values so that they all use the same ISO8601 format. That way the comparison operators will work correctly (as they do in MySQL).