xxxxxxxxxx
DECLARE @datetimeValue datetime;
DECLARE @dateValue date;
SET @datetimeValue = GETDATE(); -- Replace with your actual datetime value
SET @dateValue = CONVERT(date, @datetimeValue);
xxxxxxxxxx
select Cast( '2021-09-22' as date ) as castedDate;
select convert(date,'20210922') as convertedDate;
xxxxxxxxxx
-- 2 ways
SELECT CONVERT(datetime, '2021-01-01');
SELECT CAST('2021-01-01' AS datetime);
xxxxxxxxxx
-- Assuming we want to convert a datetime value to a specific format, such as 'YYYY-MM-DD HH:MI:SS'
-- Using the CONVERT function
SELECT CONVERT(varchar, GETDATE(), 120) AS converted_datetime;
-- Using the FORMAT function (available from SQL Server 2012 onwards)
SELECT FORMAT(GETDATE(), 'yyyy-MM-dd HH:mm:ss') AS converted_datetime;
xxxxxxxxxx
declare @Existingdate datetime
Set @Existingdate=GETDATE()
Select CONVERT(varchar,@Existingdate,103) as [DD/MM/YYYY]