Home > DeveloperSection > Forums > Converting a year string to a Datetime value
Tanuj Kumar

Total Post:134

Points:940
Posted on    November-17-2014 11:32 PM

 ASP.Net ASP.Net 
Ratings:


 1 Reply(s)
 534  View(s)
Rate this:
I am creating a simple input form to create an account. On the form there is an input field for the year the company was founded, this is a simple textbox where the user will type in the year

However on attempting to insert this to the database field which is a datetime an error is being thrown despite converting the textbox entry to datetime...

 

myCompanyAccount.Founded = Convert.ToDateTime(this.TxtCompanyFounded.Text);

Is there a way in which i can can convert a year input  to a datetime so it can be inserted to the database...? Thanks in advance! 


Sumit Kesarwani

Total Post:378

Points:2694
Posted on    November-17-2014 11:45 PM

Hi Tanuj, 
try this:

MyCompany.Founded = new DateTime(Convert.ToInt32(this.TxtCompanyFounded.Text), 1, 1);


Don't want to miss updates? Please click the below button!

Follow MindStick