Skip to main content
Solved

how to do SQL Month and Year


Forum|alt.badge.img+16

Community,

I have a SQL column RECEIPT_INFO_CFV.ARRIVAL_DATE which is showing like below, 

8/15/2022 5:14:12 PM

which function I can use in SQL to retrieve Month in a column, and Year in a column, for above sample,  SQL result should return like below,

Month       Year

8                 2022

 

Thank you.

Best answer by dsj

Hi @ronhu 

 

You can use following syntax to get month and year

select to_char(ARRIVAL_DATE , 'MM') Month,to_char(ARRIVAL_DATE , 'YYYY') Year  from RECEIPT_INFO_CFV

 

Hope it helps!

Damith

View original
Did this topic help you find an answer to your question?

dsj
Superhero (Partner)
Forum|alt.badge.img+22
  • Superhero (Partner)
  • February 27, 2024

Hi @ronhu 

 

You can use following syntax to get month and year

select to_char(ARRIVAL_DATE , 'MM') Month,to_char(ARRIVAL_DATE , 'YYYY') Year  from RECEIPT_INFO_CFV

 

Hope it helps!

Damith


Forum|alt.badge.img+16
  • Hero (Customer)
  • February 27, 2024

@dsj it is working, thank you very much.


Banu Liyanapathirana
Hero (Employee)
Forum|alt.badge.img+13

Hi @ronhu ,

 

Try EXTRACT function. see the example. 

 

SELECT 
     EXTRACT(MONTH FROM ARRIVAL_DATE) AS month, 
     EXTRACT(YEAR FROM ARRIVAL_DATE) AS year 
FROM RECEIPT_INFO_CFV;

 


Forum|alt.badge.img+16
  • Hero (Customer)
  • February 27, 2024

@Banu Liyanapathirana It is working. Thank you.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings