I have a record as '5/30/2016'. Now I want to have month and year from this date column. Output I want is as : '5/2016'. How can I do that in redshift?
1 Answer
select to_char('5/30/2016'::date,'MM/YYYY')
would give you '05/2016'
, and if you don't want the first zero you can trim it:
select ltrim(to_char('5/30/2016'::date,'MM/YYYY'),'0')
-
1You can also use the
DATE_TRUNC()
function to round the value back.SELECT date_trunc('week', '2017-07-13');
=2017-07-10 00:00:00
Commented Jul 13, 2017 at 16:58
'5/30/2016'
stored as a string (as shown), or is it a date field and'5/30/2016'
is merely how your SQL tool is displaying it?