Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

str to date - update with separate month/year

Status
Not open for further replies.

thompom

Technical User
Dec 4, 2006
395
GB
Hi,

In a table i have [stupidly] stored a date in separate month and year field, now i want to merge those fields and put them in a date field

have tried the following which puts the year in the date field - but how do i add the month aswell
[the day should be set to 01]

Code:
update table set dateadd = str_to_date(yearadd,'%Y')

thanks MG
 
I think you need to concatenate the separate parts. If you use concat_ws it automatically adds the separator.:
select str_to_date(concat_ws('/',2008,04,01),'%Y/%m/%d')

Have a look at and for details.

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
thanks for the idea john - concat got the jobdone

Code:
UPDATE table SET datenew = CONCAT(year, month, '01');
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top