Ok guys, I hope someone here can help me.
I got a bunch of XML files I have to import with this time format:
20100712 17:51:03
And according to the MYSQL docs, the correct DATETIME format is:
'YYYY-MM-DD HH:MM:SS'
As you can see, the only thing that is ruining the show for me is those hyphens between the year, month and date.
Would anyone know of a good tip to try to adapt this format to MYSQL's? I already tried importing it just like it is and MYSQL changes the date to 00-00-00 00:00:00 because it's in an invalid format.
Try STR_TO_DATE:
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date
Related
why this query gives me the wrong output although I am trying to print data between '01-May-2022' and '30-May-2022';
why is this query giving me apr data?
It appears that you are storing your dates as text. You should not be doing this, and the best long term fix is to make datee a proper date column. As a short term fix, you may use STR_TO_DATE:
SELECT datee
FROM customer_shopping_details_tbl
WHERE STR_TO_DATE(datee, '%d-%b-%Y') BETWEEN '2022-05-01' AND '2022-05-30';
Thank you all ....
I did a mistake while saving the date, I had saved the date in the string format. That is the reason that the query does not show proper output
What I learned/point to remember
-MySQL date format is yyyy-mm-dd
-Save your date in the form of date NOT IN String
go through the comments for the better idea
I have saved my data in the form of String so i have fired the following query and is working now
Good evening,
Maybe this could help:
SELECT login,datetime FROM log where datetime between
to_date(’01-jan-2004,’mm/dd/yyyy’) and
to_date(’21-jan-2004′,’mm/dd/yyy’)
order by datetime DESC;
have column which is of type date having default format as YYYY-MM-DD. I want to get date in format DD-MM-YYYY but as date type only. I would like to know how is it possible? I am combining 2 functions together as shown below but i am not getting the desired result
STR_TO_DATE(DATE_FORMAT(emp.doj, '%d-%m-%y'),'%d-%m-%y') as doj
Please dont close this questions as its a different one not asked before thanks!!!
DATE_FORMAT(emp.doj,'%d-%m-%Y') as doj
You have not need to use STR_TO_DATE. use only DATE_FORMAT. It should be work.
I want to format
1/2/55
05/06/82
9-15-58
2/12/65
02-17-1967
2007-06-12
04/29/197
dates in to MM/DD/YYYY. these are in varchar now. need to format and convert in to date. Any help please
You use mysql DATE_FORMAT() method.
Link:
https://www.w3schools.com/sql/func_mysql_date_format.asp
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
I am new to Cassandra cql (cqlsh 4.1.1, Cassandra 2.0.8.39, CQL spec 3.1.1, Thrift protocol 19.39.0) - using the cql COPY command to a table from a CSV formatted file and I get the following error: Bad Request: unable to coerce '2012/11/11' to a formatted date (long). How do I change a column using cql so that it accepts the date from my CSV file?
as Brian said, there are CQL timestamp type to follow to get CQL query running. Sometimes it looks like quite weird indeed ! I've got the same issue few weeks ago with a date time insert like this one :
INSERT INTO my_table (id,lastvisitdate) VALUES (1682221,'2012-03-25 02:26:04');
I got this error : Bad Request: unable to coerce '2012-03-25 02:26:04' to a formatted date (long) ! mmmm... so bad as the date time seems to be correct !
After many tries and before going nuts, I've just added a Z at the end of the time, Z stands for Zulu time which is also UTC and GMT :
INSERT INTO my_table (id,lastvisitdate) VALUES (1682221,'2012-03-25 02:26:04Z');
Yessss ! It works ! So do not forget the timezone in your date time values, it could be helpful ! ;-)
There is not a direct way to do that from within CQLSH.
There are a certain set of string date formats which can be coerced. See the CQL Timestamp type documentation page for some examples like:
yyyy-mm-dd HH:mm
yyyy-mm-dd HH:mm:ss
yyyy-mm-dd HH:mmZ
yyyy-mm-dd HH:mm:ssZ
yyyy-mm-dd'T'HH:mm
yyyy-mm-dd'T'HH:mmZ
yyyy-mm-dd'T'HH:mm:ss
yyyy-mm-dd'T'HH:mm:ssZ
yyyy-mm-dd
yyyy-mm-ddZ
As a workaround you could modify your CSV file to adjust the date format, then import it. (In your case it may be as simple as "yyyy/mm/dd" -> "yyyy-mm-dd".)
I got in my table two types:
hour_Event in type date
date_Event in type datetime
I would like hour_Event to be formatted to hh:mm
and date_Event to be dd/mm/yyyy
I use PHPMyAdmin and im new with MySQL so I dont know how to change the format and for what.
How do I do it?
**DATE_FORMAT(hour_Event,'%h:%i')** will give you hour_Event in hh:mm
and
**DATE_FORMAT(date_Event,'%d/%m/%Y')** will give you date_Event in dd/mm/yyyy
You could change the format using php before you insert data or after retrieving themfrom your database according to your needs.You could use DateTime / strtotime() & date(). In most cases a single timestamp field in your table is enough for an event.
Have a look here:
Convert one date format into another in PHP
Also you could format your field according to your needs with mysql for example:
DATE_FORMAT(tables.field, '%d-%m-%Y %H:%i:%s') AS 'new_name'
Have a look about it here:
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format