Get only month and day using SELECT in SQL server
Use SQL server 2008 R2
I want to make a simple select
that by means of a GETDATE()
shows a specific date format with no Year:
Day / month
This select
gives me the values but in separate columns
SELECT MONTH(GETDATE()), Day(GetDate())
I need to do it but in this example format: day 1 month December
Date
1/12
Tried this:
SELECT (MONTH(GETDATE())/ Day(GetDate())) as Fecha
The result is:
Date
0
7 answers
For SQL Server 2012+, it is best to use FORMAT
:
SELECT FORMAT(GETDATE(),'dd/MM') Fecha;
If not, you can use:
SELECT DATENAME(DAY,GETDATE()) + '/' + CONVERT(VARCHAR(2),MONTH(GETDATE())) Fecha
;
Or also
SELECT CONVERT(VARCHAR(5),GETDATE(),103) Fecha;
With this last Code, the result would be 01/12
You can use the CONCAT function:
SELECT CONCAT(MONTH(GETDATE()), '/', Day(GetDate())) as Fecha
A greeting
Worked a lot for me this way:
SELECT FORMAT(GETDATE(),'yyyy-MM-dd') as fecha;
If you do it with a field and table in specified:
SELECT FORMAT(nombre_campo,'yyyy-MM-dd') as fecha FROM nombre_tabla;
This can serve you
SELECT CAST(Day(GetDate()) AS VARCHAR(10) ) +'/'+ CAST(MONTH(GETDATE()) AS VARCHAR(10)) as Fecha
You need to convert what it shows to text first in order to concatenate the results.
For that you need to use the function CONVERT
. Applied to what you want would be:
SELECT (CONVERT(varchar(3),DAY(GETDATE()))+'/'+ CONVERT(varchar(3),MONTH(GetDate()))) as Fecha
You could try with cast or CONVERT of datetime with a Date Style, convert it to a varchar of 5 characters, so that you take the first 5 characters of dd / mm / yyyy IE take dd / MM.
Day / month example
SELECT CONVERT(VARCHAR(5),GETDATE(),103) AS FECHA
Month / day example
SELECT CONVERT(VARCHAR(5),GETDATE(),101) AS FECHA
SET LANGUAGE Spanish
SELECT CONCAT('día ', DAY(GETDATE()), ' mes ', DATENAME(month, GETDATE()))