If anyone's interested, here's a user defined function to swap the day and month around, leaving the year and time unchanged.
CREATE FUNCTION dbo.MonthDaySwap (@dt datetime)
RETURNS datetime AS
BEGIN
return convert(datetime,
convert(varchar(50),day(@dt))+'/'+
convert(varchar(50),month(@dt))+'/'+
convert(varchar(50),year(@dt))+' '+
CONVERT(varchar(12), @dt, 114)
)
END
You can use this in an update query as follows:
update dbo.Orders
set orderdate=dbo.MonthDaySwap(orderdate)
where orderid=5
1 comments:
Brilliant, many thanks
Post a Comment