---
title: "Converting a year string to a Datetime value"  
description: "Converting a year string to a Datetime value"  
author: "Anonymous User"  
published: 2014-11-17  
updated: 2014-11-17  
canonical: https://www.mindstick.com/forum/12623/converting-a-year-string-to-a-datetime-value  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 1 minute  

---

# Converting a year string to a Datetime value

I am creating a [simple](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) [input](https://www.mindstick.com/forum/159209/how-can-i-read-convert-an-input-stream-into-a-string-in-java) form to create an account. On the form there is an input field for the year the [company was founded](https://answers.mindstick.com/qa/31435/in-which-year-microsoft-company-was-founded), this is a simple [textbox](https://www.mindstick.com/forum/12714/dynamic-textbox-in-gridview) where the user will type in the year\

However on attempting to [insert](https://www.mindstick.com/blog/173/executing-insert-delete-or-update-query-in-sqlserver-using-ado-dot-net) this to the [database](https://www.mindstick.com/articles/12226/use-of-database-in-sencha-extjs-and-insert-record-from-user-form-using-ajax) field which is a [datetime](https://www.mindstick.com/forum/12949/how-to-validate-if-a-datetime-field-is-not-null-empty) an [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) 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](https://www.mindstick.com/forum/2093/configurationmanager-appsettings-convert-n-to-n-why) a year input to a datetime so it can be inserted to the database...? Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by Sumit Kesarwani

Hi Tanuj, try this:\
\

MyCompany.Founded = new DateTime(Convert.ToInt32(this.TxtCompanyFounded.Text), 1, 1);


---

Original Source: https://www.mindstick.com/forum/12623/converting-a-year-string-to-a-datetime-value

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
