Possible Duplicate:
Most efficient way in SQL Server to get date from date+time?
I want to update a field with today's date only but the problem i am having now is it is giving me the date and the time. I would like to update with specific format like this: 11/09/2012 how can i achieve this? here is my current code:
UPDATE MyTable
SET Field1 = GETDATE()
One way is to update and select only date (not time)
UPDATE @tab SET dates=(CONVERT(VARCHAR(10),GETDATE(),103));
SELECT CONVERT(VARCHAR, GETDATE(), 23) FROM @tab
Not much different here apart from slight syntax differences however I would recommend wrapping it up in a function.
CREATE FUNCTION [dbo].[GetDateOnly] (@Datetime datetime)
RETURNS datetime
AS
BEGIN
RETURN CONVERT(Datetime, FLOOR(CONVERT(float,@Datetime)))
END
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With