5

how to change multiple dateformat into one dateformat in sql?

currently, i'm using my java code. however, I would like to change using sql function so that I don't need to consume another connection between my java program and database.

My current code is below:

--

any pointer would be appreciated

goutthee
  • 329
  • 4
  • 14
  • if it's empty or null, i set empty value – goutthee Jun 21 '16 at 06:21
  • for example, if value inside birthDate[0] is '2016/01', it will give 7. if birthdate is '2016', it will give 4. it can be 0 too cuz birthDate can be 'empty' – goutthee Jun 21 '16 at 06:27
  • I tested this `DECLARE @finalDate nvarchar(20) SET @finalDate = CONVERT(varchar, '2011/01' ,111); print @finalDate;` I got 2011/01 but i want finalDate to be '2011/01/01' 'YYYY/MM/DD' format – goutthee Jun 21 '16 at 06:34
  • hey sorry, i got wrong answer your question : birthDate[0].length is checking for 'YYYY' or 'MM', if the len is 4, i assume it's year. if the len is 2, I assume 'month' – goutthee Jun 21 '16 at 07:03

1 Answers1

2

Did hardcode as below but i think it's poor code :(

DECLARE @finalDate nvarchar(20) SET @finalDate = CONVERT(nvarchar(15), '2011/01'+'/01' ,100); print @finalDate;

goutthee
  • 329
  • 4
  • 14