phpMyAdmin - I need to manually change datetime value in a column.
current value - 2018-11-03 20:47:18
desired value - 2018-11-02 20:41:50
After editing the cell and pressing Enter the result is:
2018-11-02 20:41:50.000000
I tried multiple times - seems there is no way - the nulls are always added.
The column is datetime type, without default values.
Any help?
The zeros at the end are added automatically and make no difference. PHP for example inserts DATETIME without them, but the phpmyadmin editor does. They wont affect the value itself.
If you don't wat to see the zeros, execute the following query:
UPDATE table SET column = "2018-08-20 00:00:00" WHERE id = 999
Related
I have a problem in getting the sum of one of my column names in database (PRICE). If I insert 1000.00 and 3600.00 to get the sum of them, I am getting 4.00 instead of 4600.00. But when the total is below 1000 I get the correct answer.
It appears that your price_per_case column is char or varchar column rather than a numeric column such as decimal(10,2). So, it is converting the column to double but ignoring everything after the , character (and probably issuing warnings during the conversion). You can verify this by trying the following:
select '1,234' + '3,456';
You will end up with 4;
You should try running:
update ordered set price_per_case = replace(price_per_case, ',', ''); /* get rid of commas */
Then you should change the type of this column to decimal(10,2) or some appropriate precision.
Maybe the machine when you are programming have different “Locale” of MySql Server (are both in the same machine)?
In this case also format currency/double/decimal is different.
To avoid that you need to change Locale in you .NET method/sub/function before/into you get query result
Threading.Thread.CurrentThread.CurrentCulture = New CultureInfo("it-IT")
Threading.Thread.CurrentThread.CurrentUICulture = New CultureInfo("it-IT")
or change Locale in MySql
SET lc_time_names = 'it_IT'; Here continue your query
In this example I have used Italian Locale
Doing CSV file import to SQL database/table.
There is a date column which comes over as "1899-12-30 00:00:00.000".
Date column is Nullable on the database side.
Not sure why it's still showing 1899..
I used different derived expressions and nothing seem to be working.
I want to see Null instead of "1899-12-30 00:00:00.000" in the table/database.
Pls. advice
I tried to retain Null values as Nulls in the file on Flat file source.
That resolved the issue. Not sure how I overlooked this option..
This is an option:
First just load the data into database. Don't worry about 1899-12-30 00:00:00.000.
Add a SQL Task and set the value of DateColumn to NULL wherever its "1899-12-30 00:00:00.000". I'm pretty sure you don't have actual 1899-12-30 00:00:00.000 values in your database, so you don't need to worry.
I was using a Script Component transformation task, and to make my Date column NULL I had to explicitly set its value à la
Row.ColumnName_IsNull = true;
otheriwse it defaulted to 12/30/1899.
I create in my personal MySQL DB on qnap NAS a date field with the format yyyy-mm-dd.
Sometimes I need to insert in this field date in the form 1880-00-00.
If I use a qnap phpAdmin app to connect to DB through browser I correctly see the value 1880-00-00.
But if I use a client like DBVisualizer, when I run the select on the db, in the data field I see 1879-11-30 rather than 1880-00-00.
How could I get the correct value I inserted in database?
1800-00-00 is not a valid date.
MySQL replaces it with a valid date value.
Here's an explanation of how this work behind the scenes:
1800-00-00 ==> 1799-11-30 -- substract 1 month and 1 day from valid 1800-01-01
1800-00-01 ==> 1799-12-01 -- substract 1 month from valid 1800-01-01
1800-01-00 ==> 1799-12-31 -- substract 1 day from valid 1800-01-01
1800-00-31 ==> 1799-12-31 -- substract 1 day from valid 1800-01-01
1800-01-01 ==> 1800-01-01 -- substract nothing, it's a valid date
If a date like 1800-00-00 is valid for you because you don't know month or a day when an event happened, you should consider changing your column type to varchar instead of date because in the future you are going to run into problems - especially when using ODBC. Those dates will be empty, as they are not known to that interface.
Of course, you have to be fully aware that you are giving up on building SQL queries that manipulate and calculate over date type (specific functions), but if your case is "more or less precise date" such queries wouldn't really give a stable result anyways.
I've got a table setup which has populated data. In column "date", I have dates in the following format:
yyyymmdd i.e. 20131110
I have created a new field and called it newdate with the text format.
Then, I open up the SQL window and put the following in
UPDATE wl_daily
SET
newdate = UNIX_TIMESTAMP(date)
For some reason, it is running correctly, however it only outputs NULL to all the rows. Also, the column name is blank for some reason
Any suggestions?
That's because your field in a string and you're trying to add timestamp to it which is not a string. You need to use a valid datetime field like timestamp for this to work.
Advice: don't store dates and times as strings. Store them in their native format. It makes working with dates and times much easier.
While John Cronde's answer is correct - it doesnt help your situtation
UNIX_TIMESTAMP(STR_TO_DATE(`date`, '%Y%m%d'))
will do the conversion for example
SELECT UNIX_TIMESTAMP(STR_TO_DATE('20131111', '%Y%m%d'))
returns
unix_timestamp(STR_TO_DATE('20131111', '%Y%m%d'))
---------------------------------------------------
1384128000
You should only use this to convert your columns to the date specific columns. Converting each time you need a number will add load and slow down the query if used in production
The destination table has a column named updated and is set as:
Name: updated
Type: timestamp
Attributes: on update CURRENT_TIMESTAMP
Null: No
Default: CURRENT_TIMESTAMP
Extra: ON UPDATE CURRENT_TIMESTAMP
The source data is in a CSV, where the updated field is blank for every row, e.g.
id,item_name,updated,quantity
1,car,,4
2,truck,,5
3,chair,,5
After importing using PHPMyAdmin, I expect to see the updated column filled with the current date/time when the import was executed, however, I get all 0000-00-00 00:00:00 instead.
MySQL version: 5.5.30. This result is the same with MyISAM and InnoDB.
That is because the field is supplied. It is supplied as empty string, which is something different than NULL or default.
Empty strings will be converted to 0 when cast to a numeric value. And timestamp 0 formatted as a date is 0000-00-00 00:00:00.
You can either run UPDATE table SET updated=NOW() after importing (if you always import a complete set) or remove the entire column from the CSV.
How do you do a SET updated in phpmyadmin?
With the column described above, assign each value of the update column in the CSV as "NULL". The date of csv import is then added to mySQL.
One strange thing I noticed was errors in defining in the column. Even with an empty table, it was telling me that the default value for TIMESTAMP could not be CURRENT_TIME. To fix this, I banged my head on the table three times, changed the type to datetime, saved, then re-edited, and was allowed to change the type to TIMESTAMP.
The below steps works for setting timestamps to NULL.
1. Make the default value of the column - updated as NULL (anyhow, you want the timestamp to be empty)
2. In csv file type NULL instead of keeping the field blank
This method can also be used for auto increments