Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a text representing date (mysql database Date table) i want to convert it to custom format as MM-dd-YYYY
Eg. Convert from - 9 November 2000 to 9/11/2000
also suggest me sort with date in PHPMYADMIN
Regards,
Arjun
use query like
SELECT DATE_FORMAT(STR_TO_DATE('9 November 2000', '%e %M %Y'), '%e/%c/%Y')
and for sorting use indexing or try using order by
you can use sql syntax like this to create custom date format
DATE_FORMAT(NOW(),'%m-%d-%Y') --> 07-11-2013
DATE_FORMAT(NOW(),'%d %b %y') --> 11 Jul 13
DATE_FORMAT(NOW(),'%m/%d/%Y') --> 07/11/2013
To use sort in PHPMyAdmin, you can use mysql query such as
SELECT * from TABLE_NAME order by DATE_COLUMN_NAME
Hope it helps! Good luck!
Try this:
SELECT DATE_FORMAT(STR_TO_DATE('9 November 2000', '%e %M %Y'), '%e/%c/%Y');
Check out this link for MYSQL Datetime Functions
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have a table with a column in which are inserted timestamps.
exactTime : ' 2017-12-17 05:00:12 ' and i want to change this format into '2017-12-17 05:00'
i would need some help with this .
You could use date_format for this.
select date_format(your_date,'%Y-%m-%d %H:%i')
from your_table;
Resource
You can truncate to the nearest minute using:
select str_to_date('2017-12-17 05:00:12', '%Y-%m-%d %H:%i')
To actually output without seconds, you need to convert back to a string. Or just use string operations:
select left('2017-12-17 05:00:12', 16)
SELECT date_format('2017-12-17 05:00:12','%Y-%m-%d %h:%i')
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I used Bootstrap datepicker to get date from the user. I stored that value in database.
But when i render this date in html, it showed unexpected value with the date !
I give the screen shot of the result.
Can anyone help me to solve this ?
How have you stored the date in the database?
Make sure you used DATETIME and not VARCHAR
Also how did you get the date from the database?
I would use:
$query = "SELECT DATE_FORMAT(ColumnName, '%Y-%m-%d %H:%i:%s') AS Date FROM Table";
$result = mysqli_query($cxn,$query) or die(mysqli_error());
$date = $result->fetch_object()->Date;
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a huge table I'm trying to port to a new database, there's a row that stores number of doors, body style, and gearbox like "4SDa" for 4 door sedan, auto or "5HBm" for 5 door hatchback, manual.
I need to select all rows that AREN'T like this so I can edit them as they are causing issues.
How can I select any row that isn't in the format
number-letter-letter-letter' (case insensitive)
select * from your_table
where your_column not regexp '^[0-9][a-zA-Z]{3,3}$'
Regex Tester
SELECT '4SDa' REGEXP '^[0-9][a-z]{3}$'; --> 1
SELECT '4SDaa' REGEXP '^[0-9][a-z]{3}$'; --> 0
SELECT 'AAbb' REGEXP '^[0-9][a-z]{3}$'; --> 0
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
example field in mysql table with only one row:
james is a good boy james he is good and is active
SELECT FUNCTION(field)
FROM table
should return only the unique words in the field:
james is a good boy he and active
I know how to do this using PHP.
I wish to do this using MYSQL.
Please help.
Thank you.
MySQL has little support for regular expressions, so you the resulting solution could be a little complicated:
SELECT
GROUP_CONCAT(word ORDER BY min_n SEPARATOR ' ')
FROM (
SELECT
id,
MIN(numbers.n) min_n,
SUBSTRING_INDEX(SUBSTRING_INDEX(tableName.st, ' ', numbers.n), ' ', -1) word
FROM
numbers INNER JOIN tableName
ON LENGTH(st)>=LENGTH(REPLACE(st, ' ', ''))+numbers.n-1
GROUP BY
id, word
) s
GROUP BY
id
(You need to have a numbers table). Please see fiddle here.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to fetch mysql data having round brackets e.g. ABCD(XYZ). When I run query
"SELECT * FROM tablename WHERE Column = 'ABCD(XYZ)'"
it returns an empty result. Please suggest a way. Thanks in advance!
this should work:
INSERT INTO `tablename` (`Column`) VALUES ('ABCD(XYZ)');
SELECT * FROM `tablename` WHERE `Column` = 'ABCD(XYZ)'";
Maybe 'ABCD(XYZ)' is not exactly the value of your data (for example if you inserted some whitespaces before or after it.)
You can try it with a like to find that out:
SELECT * FROM `tablename` WHERE `Column` LIKE '%ABCD(XYZ)%'";
Another possibility is that your value has been converted with htmlentities and you saved something like this:
'ABCD&40;XYZ&41;'
&40; Left parenthesis
&41; Right parenthesis