0

I have a table with expdate column which contains dates. Dates are in different formats i.e. 01-Apr-17 12:00:00 AM , 02/2017, 3/1/2017 12:00:00 AM.. I want to extract date from this table in mm/yy format..

Matt
  • 14,906
  • 27
  • 99
  • 149
piya
  • 1
  • 1
  • 2
    Dates have no format. Store them as `datetime` instead of `varchar`. Which rdbms are you using at all? – Tim Schmelter Jan 05 '16 at 09:47
  • This is not a problem for SQL, in my opinion. Extract the dates and format them in a more appropriate language (your choice). PHP has e.g. `strtotime()` and `date()` for that purpose. – some-non-descript-user Jan 05 '16 at 09:51
  • Please provide the code and let us know which part is problematic. As it stands now the question is hard to answer. – Onots Jan 05 '16 at 09:55
  • case when len(expirydate)=21 then cast(month(expirydate) as varchar)+'/'+cast(right(year(@date),2) as varchar) else cast(LEFT(substring(@date, patindex('%[^0]%',@date), 10), CHARINDEX('/', substring(@date, patindex('%[^0]%',@date), 10), 0)-1) as varchar)+'/'+cast(right(@date,2) as varchar) end as 'date' – piya Jan 05 '16 at 10:55
  • Possible duplicate of [How to convert DateTime to VarChar](http://stackoverflow.com/questions/74385/how-to-convert-datetime-to-varchar) – Tom Brunberg Jan 05 '16 at 17:49
  • did you tried this https://msdn.microsoft.com/en-us/library/ms187928.aspx – Arun Chandran Chackachattil Jan 07 '16 at 10:27
  • Which DBMS are you using? –  Jan 07 '16 at 10:31

0 Answers0