SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


PROBLEM WITH DATE CONVERSION


PROBLEM WITH DATE CONVERSION

Author
Message
lonhanner
lonhanner
Valued Member
Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)

Group: General Forum Members
Points: 61 Visits: 144
I have a column called "UP_DATE". When the code below trys to read "UP_DATE" I get the following
riders.UP_DATE = CDate(reader("UP_DATE").ToString)

error. Conversion from string "" to type date is not valid. It looks as its tring to convert time. here is the data I get. riders.UP_DATE #12:00:00 AM#. Anyone have a solution to how to fix this column
.
When i query the data in SQL server manegement it displays the date fine. I have other date fields and they convert ok.
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25897 Visits: 17517
lonhanner (12/27/2012)
I have a column called "UP_DATE". When the code below trys to read "UP_DATE" I get the following
riders.UP_DATE = CDate(reader("UP_DATE").ToString)

error. Conversion from string "" to type date is not valid. It looks as its tring to convert time. here is the data I get. riders.UP_DATE #12:00:00 AM#. Anyone have a solution to how to fix this column
.
When i query the data in SQL server manegement it displays the date fine. I have other date fields and they convert ok.


What is this code and what does #12:00:00 AM# mean? That looks like data from Access or something.

The error message is however pretty self explanatory. Whatever is reading your table it is getting an empty string in reader("UP_DATE") which can't be cast to a datetime object in many languages. t-sql will convert an empty string to 1/1/1900 but .NET will throw an exception when parsing a date from an empty string.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
lonhanner
lonhanner
Valued Member
Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)

Group: General Forum Members
Points: 61 Visits: 144
Yes the data came from ACCESS. I imported to sql. Is their anyway I can convert the "UP_DATE" Column to the sql date type. If so could you give me an example query to do this.

Thanks
Lon
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25897 Visits: 17517
lonhanner (12/27/2012)
Yes the data came from ACCESS. I imported to sql. Is their anyway I can convert the "UP_DATE" Column to the sql date type. If so could you give me an example query to do this.

Thanks
Lon


Not sure what datatype it is now or if everything in it will convert correctly but...


alter table MyTable
alter column MyColumn datetime



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search