Get only month and day using SELECT in SQL server

2

Use SQL server 2008 R2

I want to make a simple select that using a GETDATE() show a specific date format without 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

I tried this:

SELECT (MONTH(GETDATE())/ Day(GetDate())) as Fecha

the result is:

  

Date
  0

    
asked by Juan Carlos Villamizar Alvarez 26.10.2016 в 16:23
source

7 answers

6

For SQL Server 2012+, it's 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

    
answered by 26.10.2016 / 16:31
source
2

You can use the CONCAT function:

SELECT CONCAT(MONTH(GETDATE()), '/', Day(GetDate())) as Fecha

Greetings

    
answered by 26.10.2016 в 16:29
1

It worked for me a lot like this:

SELECT FORMAT(GETDATE(),'yyyy-MM-dd') as fecha;

If you do it with a field and table in specific:

SELECT FORMAT(nombre_campo,'yyyy-MM-dd') as fecha FROM nombre_tabla;
    
answered by 13.04.2018 в 22:23
0

This can help you

SELECT CAST(Day(GetDate()) AS VARCHAR(10) ) +'/'+ CAST(MONTH(GETDATE()) AS VARCHAR(10)) as Fecha
    
answered by 26.10.2016 в 16:30
0

You need to convert what it shows to text first to be able to concatenate the results.

For that you must use the function CONVERT . Applied to what you want would be:

SELECT (CONVERT(varchar(3),DAY(GETDATE()))+'/'+ CONVERT(varchar(3),MONTH(GetDate()))) as Fecha
    
answered by 26.10.2016 в 16:33
0

You could try CAST or CONVERT from 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 that is to say it would take dd / mm.

Example of day / month

SELECT CONVERT(VARCHAR(5),GETDATE(),103) AS FECHA 

Month / day example

SELECT CONVERT(VARCHAR(5),GETDATE(),101) AS FECHA
    
answered by 26.10.2016 в 16:34
-1
SET LANGUAGE Spanish
SELECT CONCAT('día ', DAY(GETDATE()), ' mes ', DATENAME(month, GETDATE()))
    
answered by 26.10.2016 в 16:36