I have a query in SQL
, I have to get a date in a format of dd/mm/yy
Example: 25/jun/2013
.
How can I convert
Try this
select convert(varchar,getdate(),100)
third parameter is format, range is from 100
to 114
, any one should work for you.
If you need date in dd/mmm/yyyy
use this:
replace(convert(char(11),getdate(),113),' ','-')
Replace getdate()
with your column name. This worked for me.
Simply get date and convert
Declare @Date as Date =Getdate()
Select Format(@Date,'dd/MM/yyyy') as [dd/MM/yyyy] // output: 22/10/2020
Select Format(@Date,'dd-MM-yyyy') as [dd-MM-yyyy] // output: 22-10-2020
//string date
Select Format(cast('25/jun/2013' as date),'dd/MM/yyyy') as StringtoDate // output: 25/06/2013
Source: SQL server date format and converting it (Various examples)
Try using the below query.
SELECT REPLACE(CONVERT(VARCHAR(11),GETDATE(),6), ' ','/');
Result: 20/Jun/13
SELECT REPLACE(CONVERT(VARCHAR(11),GETDATE(),106), ' ','/');
Result: 20/Jun/2013
we can convert date into many formats like
SELECT convert(varchar, getdate(), 106)
This returns dd mon yyyy
More Here This may help you
Anyone trying to manually enter the date to sql server 'date type' variable use this format while entering :
'yyyy-mm-dd'