I need to convert this date time (2022-01-28 06:04:48) to date (2022-01-28) in SQL. How can I do that?
CodePudding user response:
You can use DATE_FORMAT(date, format) function to format your date accordingly
Example
SELECT DATE_FORMAT('2022-01-28 06:04:48', "%Y-%m-%d") as mydate;
Result
CodePudding user response:
You can convert it like this
declare @Existingdate datetime
Set @Existingdate=GETDATE()
Select CONVERT(varchar,@Existingdate,23) as [yyyy-mm-dd]
and also read this doc
https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date
CodePudding user response:
You can cast the datetime to date type, that will get rid of the time:
select cast(getutcdate() as date);
CodePudding user response:
If your input is a string, simply do:
SELECT DATE('2022-01-28 06:04:48');

