Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

SQL Query Date Formatting

$
0
0

Hi,

I am new to this forum and would appreciate some guidance please.

Recently in a new project I am working on, I converted an Oracle query to sql server query. I am having an issue on formatting my date field.

Currently,

SELECT REPLACE(RIGHT(CONVERT(VARCHAR(7),CONVERT(VARCHAR(7),MyDateColum),113),8),'','') AS JudgmentMonth
FROM myTable
WHERE MyDateColumn between 'yyyy-mm-dd' and 'yyyy-mm-dd'
GROUP BY REPLACE(RIGHT(CONVERT(VARCHAR(7),CONVERT(VARCHAR(7),MyDateColum),113),8),'','')

The Output is in following format

2018-01 
2018-02 
2018-03 

etc I want to change mm which is int to 3 lettered Month string so something like

Jan 2018 
Feb 2018 
Mar 2018

Can anyone help on how to achieve this?

Thanks



Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>