mysql - How to make a query that automatically create another column and convert date format? -
i have date column attribute in calendar_table store date, want add column date_name
, populate of them automatically below.
date: 2017-07-28 date_name
28 july, friday
currently using heidisql (mysql)
i tried queries below there syntax error
select [date], datename(day, [date]) + ' ' + datename(month, [date]) + ', ' + datename(dw, [date]) [dbo].[datestable]( -- current month calendar table dateadd(dd,1,eomonth (getdate(), -1)), eomonth (getdate()) ) select cd.date calendar_table cd insert cd.date_name values ( cast(datepart(day,datetime) varchar(2)) + ' ' + cast(datename(month,datetime) varchar(12)) + ','+ cast(datename(day,datetime) varchar(8)))
if want convert date default format yyyy-mm-dd
(example: 2017-07-28
) other text format 28 july, friday
have use date_format(date,format)
function.
example:
select @dt:=cast( '2017-07-28' date ) dt , date_format( @dt, '%d %m, %w' ) formatted_date_string
output in following format:
+------------+-----------------------+ | dt | formatted_date_string | +------------+-----------------------+ | 2017-07-28 | 28 july, friday | +------------+-----------------------+
you can use same or similar format in transactions.
suggestion not store formatted date strings database date , times in default formats. can apply formats on fields views , prints.
Comments
Post a Comment