FYI - I'm still a database newbie. That said, One of my MySQL tables has a column called "FirstDetect"
This column houses dates and times in the following format "2017-31-08 14:30:05". I'm importing a CSV file and everything is working just fine. However, some of the dates are not being accepted and the date value is reverted to 0000-00-00 00:00:00.
I assume it has something to do with the field settings. I can manually type this date (2017-05-09 00:17:42) into a field under the FirstDetect column, save the results and that date is written to that field as expected.
However, when I try to manually type this date (2017-31-08 14:30:05) into a field under the FirstDetect column, save the results, it reverts back to 0000-00-00 00:00:00. Anyone know what's going on here?
I'm using MySQL version 5.5.57
Default format that datetime field uses is YYYY-MM-DD HH:MM:SS. If you're trying to enter your dates in YYYY-DD-MM format, it's not going to work and it's probably going to be reverted as you described.
You can learn more from the link below.
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
Related
In our app, we use Django 1.11 and mySQL.
In our production, we encounter a problem with the date format for a couple of columns.
For some record the returned format of DateTime field is in the form: 2018-03-03T14:48:43Z and for others 2019-06-19T14:28:46+01:00.
We would like to return only one format and I think that we prefer this: 2019-06-19T14:28:46+01:00.
How to easily update the older record to use the new format?
I am importing data from a CSV file into an Access table and comparing them to data imported into a second Access table from a second CSV file.
This all works perfectly in the latter part of the month. However in the first part of the month I get varying results. Before the 13th of the month data is imported as mm/dd/yyyy whilst after this date it is imported as dd/mm/yyyy.
e.g on 20th Jan the date appears as 2016-01-20 in the csv file and imports as 20/01/2016 whereas on the 6th Jan the date appears as 2016-01-06 in the csv file and when imported into the access tables it will import as 06/01/2016 into one but 01/06/2016 into the other.
Both tables are in the same database and are configured the same. Has anybody else come upon this and more importantly could you resolve it?
This is a constant source of frustration for me in MS access: DATE MONTH management. Microsoft wasn't smart at all on that move.
The problem: Dates are ALWAYS stored as MM/DD/YYYY in the tables, no matter what you do or what your current locale is. If you see your dates as DD/MM it is because Access knows that your system locale is DD/MM and presents the dates like that to you.
For US there's no problem. For EU and mostly the rest of the world there are a lot of problems.
When Access inserts a date, it always consider that it is in the US format MM/DD, when it's not, YOU should format the date correctly. that's fine. BUT, when it find a date for which the MM/DD format isn't possible (month greater than 12), it understands that the date isnt MM/DD but rather DD/MM, and do the conversion itself ! This move in fact, is not smart at all. It is way better to have all dates incorrect or to throw an error, so you can patch directly, rather than have half of your dates correct and the other half incorrect and sometimes notice it months latter. Rant ended.
The solution:
When you make manual INSERTS of dates in your tables, you should do a
format(thedate,"MM/DD/YYYY")
When you import from a text/CSV file, you should specify that your date format is DMY.
You can do that in the import wizard, at step 3 or 4, with the button "advanced" that lies at the bottom.
I have tried multiple ways of formatting/retrieving just the TIME portion of a DATETIME function without success. Everything I have read online says CURTIME() will return the current time. It does, but returns the date as well. I have no interest in the date, as the field I am filling is a time only field. Granted the field type is DATETIME.
When I run my code, I view my table through Access 2007. I see the date as well as the TIME portion. When I do the CURDATE() function for my Date field it shows just the DATE just fine.
I have extensively googled this issue of having the DATE portion appear, but every single seemingly 'fix' to the issue is the same thing over and over, ie. Casting/converting (CONVERT doesn't seem to be a function in the current MySQL ODBC version I am using). When attempting to be simple and UPDATE the time with a string, simply nothing shows up in the Field when I refresh the Access tables.
Anyone have any ideas? Google has failed me.
Figured it out... For what ever reason the only spot for formatting that would be accepted was in the format field in the Design View from the Access 2007 view of the tables. hh:mm:ss AM/PM was necessary in the format field, apparently this is the only way to format a CURTIME() or any DATETIME function from a C# into the SQL/database I was using at least.
For "date1" attribute of my table I am trying to insert date of the format
YEAR-MONTH-DAY HOUR:MIN:SEC
Do I have ot define this format in the schema?
All I have done is
date1 DATE NULL
I know I can use DATE_FORMAT(), but I think only for retrieving/querying purposes.
What about recording data in the table?
if you are trying to insert a date with the time you need to instantiate it with datetime
date1 DATETIME NULL
SEE DOCS
alternatively you can store it as a TIMESTAMP. both store in that format
Your schema is fine (though you'll need DATETIME if wanting to preserve the time component), there aren't formatting options for how a DATETIME type is stored.
As long as the data you're inserting has a valid datetime format (the one you posted is fine) then you don't need to do anything else. Some non-standard formats will require a fix prior to insert.
The DATE_FORMAT() function is for displaying a DATE/DATETIME in a chosen format, but how the data is stored is defined solely by the data type.
I have a simple problem for which I found a solution in early testing but cannot replicate now that I need to do it for real.
We are moving our news system from CuteNews to our self-built MySQL system. All the news has been imported into the database but the date field is Timestamp. I have created a new field (created_date) and want to populate this from the Timestamp in the date field.
As I said, I did do this previously in an early trial run and was convinced that the query I used, via PhpMyAdmin was along the lines of UPDATE News set created_date=UNIX_TIMESTAMP(date). This is probably slightly wrong as I am at work and posting from my phone but it was along those lines.
No errors were returned but all 'created_date' fields were populated as 0000-00-00 00:00 not with the date taken from the Timestamp in the date field.
I know it is simple and know the answer will be obvious when I see it but any pointers would be gratefully appreciated!
Steve.
EDIT: reading back through I realised a bit of what I posted may be misleading. In my original trial run using the update query put the correct DateTime in the field based on the corresponding Timestamp field. It is only this time that it shows 0000-00-00 00:00.
Ps. Thanks for the format tidy-up. It's a bit awkward on a phone!
I knew I was nearly there!! It was not UNIX_TIMESTAMP but FROM_UNIXTIME I was after.
UPDATE news SET created_date = FROM_UNIXTIME(date)
Thanks for the help.
Steve