Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting only day and month from a date field

Tags:

sql

oracle

I have a set of dates that are in the format DD-MMM-YYYY. I need to be able to compare dates by using only the DD-MMM part of the date, since the year isn't important.

How would I achieve this?

I have tried reading up on the DATEPART function (edit: which evidently wouldn't work) but I can only theoretically get that to return either the DD or the MMM parts, not both of them at once.

Edit: added oracle tag. Sorry.

Example of date field: 01-MAR-1994

like image 875
rakeshisu Avatar asked Nov 30 '22 20:11

rakeshisu


2 Answers

If your column is of type DATE then it doesn't have a format.

If I understand you right, then you want to view the mon-dd part only, so you need to convert it with TO_CHAR function,
i.e.:

select to_char(your_date_column, 'mon-dd') from your_table
like image 159
A.B.Cade Avatar answered Dec 04 '22 08:12

A.B.Cade


Convert your dates using the following format, it will only month and the date part. You have to replace getdate() with you date fields.:

  select convert(varchar(5),getdate(),110)
like image 43
Sonam Avatar answered Dec 04 '22 08:12

Sonam