Convert mm/dd/yyyy string into timestamp in MySQL [closed] - mysql

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 6 years ago.
Improve this question
I have a column in a MySQL table where dates are stored as a mm/dd/yyyy string. I need to preserve that column as is, so I have added a new column where I want to store that date as a timestamp. What would the query look like to take column a and convert it to a timestamp and put it into the new column b?

you can use STR_TO_DATE to convert your string like
select str_to_date('02/22/2013','%m/%d/%Y');
UPDATE YourTable set newCol = str_to_date(yourOldCol,'%m/%d/%Y');

Related

MySQL query insert current time [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 last year.
Improve this question
This format in database:
Display date some like this:
Below I have mysql query
$sql = "INSERT INTO payment (user_id, course_id, amount, data_added)
SELECT user_id,course_id,monthly_subscription_fee,here_i_need_get_current_time
FROM enrol
WHERE active_shop='1'";
Can anyone help me how can I generate current time in the same format as above screen in position here_i_need_get_current_time
Use:
SELECT DATE_FORMAT(FROM_UNIXTIME(1642633200),'%a,%d-%b-%Y');
Replace 1642633200 with your column name date_added
First you need to convert your date using FROM_UNIXTIME and then give your desired format using DATE_FORMAT
Result:
DATE_FORMAT(FROM_UNIXTIME(1642633200),'%a,%d-%b-%Y')
Wed,19-Jan-2022
Demo
Check MySQL doc for more info

Returning a Decimal Value in a stored procedure [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 2 years ago.
Improve this question
I am trying to return a value that is a sum of decimal value in SQL Server 2008. I've tried using convert but it doesn't help. Here is the relevant code snips:
#ActivitySum dec (18,2) OUTPUT)
AS
SELECT
#DistinctActivities = COUNT(DISTINCT [Activities].[Activity ID]),
#Activities = COUNT([Activities].[Performer Activity ID]),
#ActivitySum = SUM(Activities.[Score])
FROM
Scenes
INNER JOIN
Every time I execute, if the sum of score has value after the decimal point, the value gets rounded to a whole number.
Any thoughts or solutions?

How to return 'year' from the date if the date format is (dd-mm-yyyy) in mysql [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 2 years ago.
Improve this question
I am trying to show the dates in (YYYY-MM-DD) format which is stored in (DD-MM-YYYY) format in the table.
Also please explain how to use year() function on (DD-MM-YYYY) date format.
assuming your data type is a string then you could use
for format(DD-MM-YYYY)
select year(str_to_date(yourcol, '%d-%m-%Y'))
or for format (YYYY-MM-DD)
select year(str_to_date(yourcol, '%Y-%m-%d'))

How to convert a particular column in table from hex to decimal in sql [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 3 years ago.
Improve this question
I have a query of 15 columns and one of them has a hexadecimal value, i wanted to convert it to decimal or int. How can i do it
You can also use
SELECT CONVERT(INT, *rowName*) AS Converted *rowName*;
EDIT:
CONVERT works with MS SQL
CONV(num, base, to) is for MySQL
SELECT CONV(*rowName*,16,10) AS Converted *rowName*;
use CONV()
CONV(num , from_base , to_base );
select SELECT CONV('b',16,10)'Hexadecimal to Decimal'

Integer to Datetime SQL [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 5 years ago.
Improve this question
I need convert this integer "1469416462" to datetime in format dd-mm-yyyy hh:mm:ss . Any ideas?
My Intent:
select CONVERT (datetime,1469416462)
The value 1469416462 looks like a Unix-Timestamp.
Unix-Timestamp: Seconds since 1.1.1970
So the solution would be easy like:
For MySQL:
SELECT from_unixtime(1469416462)