2

I would like to set up a schema which will store the current date as a string fitting in a varchar column of size 10. However CURDATE() returns as a date type, is there any way I can convert this when creating a table to automatically convert this to a string?

For reference I am using MonetDB and declaring the column like below, can I cast CURDATE somehow when creating a table?

 tdate     varchar(10)   default  CURDATE()  ,
Mihai
  • 26,325
  • 7
  • 66
  • 81
Gadesxion
  • 391
  • 2
  • 6
  • 18
  • Why would you store data as string? – Mihai Apr 17 '14 at 22:26
  • Mihai, the string format is for compatibility with some old code. I am also storing as a date datatype for practical purposes, but the string representation is also necessary for compatibility. – Gadesxion Apr 22 '14 at 19:49
  • Maybe use trigger with DATE_FORMAT http://stackoverflow.com/questions/2392413/convert-datetime-value-into-string-in-mysql – Mihai Apr 22 '14 at 19:52

1 Answers1

1

This works fine

create table dateexample ( id int identity(1,1), empname varchar(100), dateinserted varchar(10) DEFAULT (CONVERT(VARCHAR(10),GETDATE(),101)) )

insert into dateexample (empname) values ('johny')

select * from dateexample -- 1 johny 04/24/2014

Kihtrak J
  • 132
  • 1
  • 2
  • 7