September 30, 2009 at 10:04 pm
I am trying to run a simple convert statement for use in a stored procedure. I just want to display some date data (data type = varchar) in the format dd Mon yyyy. I can convert satisfactorily when using getdate() as a test, but not on my field (OA.ApprovalISODate2). Can you please explain to what is wrong with my convert statement?
selectconvert(varchar(10),OA.ApprovalISODate2, 106),
convert(varchar(10),getdate(), 106)
fromObjAccession OA
Results as below:
OA.ApprovalISODate2
1988-01-28
Getdate
01 Oct 200
September 30, 2009 at 10:07 pm
sfletcher-933270 (9/30/2009)
I am trying to run a simple convert statement for use in a stored procedure. I just want to display some date data (data type = varchar) in the format dd Mon yyyy. I can convert satisfactorily when using getdate() as a test, but not on my field (OA.ApprovalISODate2). Can you please explain to what is wrong with my convert statement?selectconvert(varchar(10),OA.ApprovalISODate2, 106),
convert(varchar(10),getdate(), 106)
fromObjAccession OA
Results as below:
OA.ApprovalISODate2
1988-01-28
Getdate
01 Oct 200
Yes... you must first cast your VARCHAR date to datetime and then the CONVERT will work. As a side bar, this is the very reason why you should not store dates in tables as VARCHARS.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 30, 2009 at 11:07 pm
Hi Jeff
Thanks very much for your help. I thought it was something quite simple, but couldn't get my head around it. Have used the cast convert statement and get the results that I need. Point taken re should not store dates in tables as VARCHARS, but I am working with a purchased database and we are stuck with the given structure.
kind regards, Sally
October 1, 2009 at 12:23 am
I kind of figured it was something like that. I've run into that type of problem with 3rd party vendors more than once.
Anyway... glad it worked out and thanks for the feedback.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 1, 2009 at 1:56 am
Hi,
how is the date column stored in table,dd/mm/yyyy or mm/dd/yyyy.
convert varchar to datetime,not directly.
Make seperate table with same structure,only change will varchar to datetime column.
Then transfer the whole data to new table via script.
Worst scenario is when varchar column contain date in dd/mm/yyyy,manipulation is very difficult.
[font="Verdana"]Regards
Kumar Harsh[/font]
October 1, 2009 at 7:55 am
I just had a thought about this, Sally... can you add a calculated column to the table without it breaking the 3rd part app?
Another possible "trick" would be to make a view of the table with the conversion already done in the view just to make future programming for you folks a little easier.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 1, 2009 at 7:20 pm
Hi Jeff
Thanks for this suggestion. I will make a view with this conversion and a couple of other similar ones so that I don't have to rack my brains again on this particular issue.
Kind regards, Sally
October 2, 2009 at 12:16 pm
Thanks for the feedback, Sally.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply