Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert SQL getdate() function into a string in dd/mm/yyyy format?

Tags:

sql-server

How do I convert SQL getdate() function into a string in dd/mm/yyyy format?

like image 969
sleath Avatar asked Feb 28 '11 15:02

sleath


People also ask

Can we convert date to string in SQL?

In order to convert a DateTime to a string, we can use CONVERT() and CAST() function. These functions are used to converts a value(of any datatype) into a specified datatype.

What format is Getdate ()?

SQL Server GETDATE() Function The GETDATE() function returns the current database system date and time, in a 'YYYY-MM-DD hh:mm:ss. mmm' format.


3 Answers

Try:

select convert(varchar(10),getdate(),103) 

There's more info on the different conversion codes here.

like image 77
Jon Egerton Avatar answered Oct 07 '22 18:10

Jon Egerton


Use conversion code 103

convert(varchar, getdate(), 103) 
like image 22
Adam Robinson Avatar answered Oct 07 '22 20:10

Adam Robinson


this worked for me

replace(convert(char(11),getdate(),113),' ','-')
like image 38
Chethan Avatar answered Oct 07 '22 19:10

Chethan