Mysql workbench timestamp change format [closed] - mysql

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')

Related

Open Json a Json field in SQL Server to table [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have a table in SQL Server where a row contains a Json column - something like this:
ResponseText
RequestId
{"LosUnqCod":0,"LosMidId":23}
96173722
{"LosUnqCod":1,"LosMidId":5}
96173721
I want to have a table in this shape:
LosUnqCod
LosMidId
RequestId
0
23
96173722
1
5
96173721
how to open this json?
Hi every body I found my answer and want to share with anyone who has the same issue as I does
SELECT
reqTbl.LosUnqCod ,
a.RequestId
FROM [dbo].[a] CROSS APPLY
OPENJSON( dbo.a.responsetext)
WITH (
LosUnqCod nvarchar(50)
) AS reqTbl
You don't have to use OPENJSON if you only have one JSON object (not an array) per SQL row, you can use JSON_VALUE instead:
SELECT
JSON_VALUE(a.responsetext, '$.LosUnqCod') LosUnqCod,
JSON_VALUE(a.responsetext, '$.LosMidId') LosMidId,
a.RequestId
FROM [dbo].[a];

how to edit my links (sort and change by starting alphabet) in sql database [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
The community reviewed whether to reopen this question 11 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
i have a database (mysql) with links like:
mysite.com/Movies/Abajan_1080p.mp4
mysite.com/Movies/Abajan_720p.mp4
mysite.com/Movies/Abajan_480p.mp4
mysite.com/Movies/Bahman_1080p.mp4
mysite.com/Movies/Bahman_720p.mp4
mysite.com/Movies/Bahman_480p.mp4
....
i sorted my files by creating directories by alphabets (A,B,...)
so i need to change links:
mysite.com/Movies/A/Abajan_1080p.mp4
mysite.com/Movies/A/Abajan_720p.mp4
mysite.com/Movies/A/Abajan_480p.mp4
mysite.com/Movies/B/Bahman_1080p.mp4
mysite.com/Movies/B/Bahman_720p.mp4
mysite.com/Movies/B/Bahman_480p.mp4
is there a simple solution to edit database? to edit all links like that?
Thanks a lot
You can use the function SUBSTRING_INDEX() to get the filename and then concatenate the path:
UPDATE tablename
SET col = CONCAT(
'mysite.com/Movies/',
LEFT(SUBSTRING_INDEX(col, '/', -1), 1),
'/',
SUBSTRING_INDEX(col, '/', -1)
)
Replace col with your column's name.
See the demo.
Results:
col
mysite.com/Movies/A/Abajan_1080p.mp4
mysite.com/Movies/A/Abajan_720p.mp4
mysite.com/Movies/A/Abajan_480p.mp4
mysite.com/Movies/B/Bahman_1080p.mp4
mysite.com/Movies/B/Bahman_720p.mp4
mysite.com/Movies/B/Bahman_480p.mp4

SQL plages de dates [closed]

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 4 years ago.
Improve this question
I ask myself why this request
SELECT * FROM world.city WHERE '20181109' > datedebut and '20181109' < datefin;
doesn't return the same result as this
SELECT * FROM world.city WHERE datedebut < 20181109 < datefin;
The last select sentence is not valid SQL, but mathematically it is the optimal solution
For each operator (ie < or > ) there must be a distinct right and left side.
When you write datedebut < 20181109 < datefin it is parsed as datedebut < 20181109 and the result of that comparison is sent to the next operator.
You need to think differently when writing SQL than when writing mathematics. You can argument that both "languages" have parsers, but they are slightly different.
EDIT comment:
As I have been made aware in the comments, My original answer was not entirely correct, since that would ave given a parse error. The essence is correct: Your query is not being parsed as you expected.
As others have answered, if you want a more compact answer, you need to use the BETWEEN keyword instead of the <and > operators.
There is a MySQL expression syntax which more closely matches your second form, which is BETWEEN:
SELECT * FROM world.city WHERE '20181109' BETWEEN datedebut AND datefin

Replacing null by zero [closed]

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 8 years ago.
Improve this question
I need to write a query which need to replace email result by 0 when it's null
UPDATE tblName SET email = 0 WHERE email is null;
Use the ifnull() function:
ifnull(email,"0")
You can use the coalesce function:
SELECT COALESCE(email, '0') FROM some_table

Convert - 9 November 2000 to 9/11/2000 [closed]

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