.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Pankaj Mishra
alex morco
Imran Ghani
Post New Web Links

string not converting in datetime format

Posted By:      Posted Date: October 01, 2010    Points: 0   Category :ASP.Net

hi to all,

 i'm developing a website. i have a registration form where user can registered with this website.

this have a birthdate field for store user's birthdate.that is a textbox.

here is my code.

protected void submitbtn_Click(object sender, ImageClickEventArgs e)
System.Globalization.CultureInfo en = new System.Globalization.CultureInfo("en-GB");
li.fname = firstname.Text;
li.lname = lastname.Text;
li.gender = gender.SelectedItem.Text;
li.date = Convert.ToDateTime(birthdate.Text,en); //getting error here
li.address = addrs.Text;
li.contactno = contno.Text;
li.countryid =Convert.ToInt32( dropcontry.SelectedValue);
li.stateid = Convert.ToInt32( dropstate.SelectedValue);
li.cityid =Convert.ToInt32( dropcity.SelectedValue);
li.emailid = prmrmailid.Text;
li.username = createuserid.Text;
li.password = createpassword.Text;
li.secutityque = dropsecque.SelectedItem.Text;
li.securityans = secanswer.Text;

int a = li.personid;
li.personid= a;
int p = li.personid;

View Complete Post

More Related Resource Links

Convertion failed when converting datetime to String

DECLARE @usr datetime SET @usr = user+'::Date' IF NOT EXISTS (SELECT 'X' FROM table WHERE Name = 'File' AND CONVERT(varchar,DateAdd, 101) = CONVERT(varchar, getdate(), 101)) BEGIN INSERT INTO table (Code, Name, Date) VALUES ('DD', 'File',@usr) END the date will be created by another process and its value will be loaded in the variable DATE. I'm calling that variable here. I;m getting the error Convertion failed when converting datetime to String. how to resolve this..??

Convertion failed when converting datetime to String

DECLARE @usr datetime SET @usr = user+'::Date' IF NOT EXISTS (SELECT 'X' FROM table WHERE Name = 'File' AND CONVERT(varchar,DateAdd, 101) = CONVERT(varchar, getdate(), 101)) BEGIN INSERT INTO table (Code, Name, Date) VALUES ('DD', 'File',@usr) END I;m getting the error Convertion failed when converting datetime to String. how to resolve this..??

Converting string to DateTime

Hello, I am trying to figure out the best way to convert a string object into a DateTime with only using the year.I have something like:Date Time HSYear = DateTime.ParseExact(HighSchoolyear, "yyyy", System.Globalization.CultureInfo.CurrentCulture); But it is still giving a "String was not a recognized as a valid DateTime."In the full context, I have a webpage with a formview on it and within the formview is a TextBox control that is taking a user input such as "1999"  then an ObjectDataSource picks it up and runs it through a BLL. And within the BLL is where I am trying to convert it before it gets inserted into the database.

converting string to datetime and then to shortdate?/

Hi,I have a field (varchar) field that holds date.  Some data was transferred to this column but the transferred data was a timestamp (datetime in the format of say 10/26/2009 4:54:13 AM).  Now, I need to modify the new table to only contain 10/26/2009.  How can I write a statement to delete the time leavin gonly 10/26/2009??  I can use trim function but the # of characters vary as the date might be 1/10/2010 12:50:00 PM, etc....?thanks .

datetime formating with string.format


I have a table in my SQL DB that is a DateTime table, what I want to do is take the numeric datetime it stores and convert it to a long date (i.e. 12/12/2012 conversts to December 12, 2012). Seaching the forums it looks like the string.format is the way to go and searching for info on that I found http://www.csharp-examples.net/string-format-datetime/ which lists all the different formats but they do not list a formating string to convert to the format I want to use. Does anyone know what format string I would use to convert a numeric date to a long date like I want? And can you show it in a code example because I am not 100% sure I understand the code examples shown on that site.

dateTime string format


when my system date separator set to "-", the following return the date format with "dd-mm-yyyy HH:mm"

DateTime b = DateTime.ParseExact(date, "dd/MM/yyyy HH:mm", provider);
                            strDate = b.ToString("dd/MM/yyyy HH:mm");

return strDate;


why? how can i return the dayeformat with "/" separator ingore PC datatime setting

Conversion failed when converting datetime from character string. SQL Server @StartDate as datetime



Can you please help me on this?

When I try to pass my parameter it doesn't work. See below is my code :


declare @SQL Varchar(4000)

declare @CRM_FilteredAppointment nvarchar(2000)

declare @CRM_FilteredSystemUser nvarchar(2000)

declare @StartDate datetime

declare @EndDate datetime

set @CRM_FilteredSystemUser = 'Select * from FilteredSystemUser'

set @StartDate = '20080101'

set @EndDate = '20100101'

set @CRM_FilteredAppointment = 'SELECT activityid, participationtypemask 

FROM FilteredAppointment 

WHERE FilteredAppointment.eu_calltype = 2

AND FilteredAppointment.statecode = 1

AND FilteredAppointment.scheduledend >= DateAdd( month, -1, GetD

Converting datetime to var``char without changing the format


Hi Team,

Is there a way to change the datetime to varchar without changing the format

like datetime '2009-09-28 00:00:00.000' after converting to varchar it should be in the same format



How to format datetime & date with century?

Execute the following Microsoft SQL Server T-SQL datetime, date and time formatting scripts in Management Studio Query Editor to demonstrate the usage of the multitude of temporal data formats available and the application of date / datetime functions.


WebMatrix conversion failed when converting from a character string to uniqueidentifier?


I am trying to retrieve xml from a small function in my .cshtml page. Its throwing me an error. This however, runs fine in a console/form environment.

It takes 3 parameters and 1 exception.

myDll.GetXML(year, username, uniqueidentifier, out ex);

When I run this page I get the error, "Conversion failed when converting from a character string to uniqueidentifier."

Or a stack of.

System.Data.SqlClient.SqlException (0x80131904): Conversion failed when converting from a character string to uniqueidentifier.

   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)

   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)

   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()

   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)

   at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()

   at System.Data.SqlClient.SqlDataReader.get_MetaData()

   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)

   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBeha

Input string was not in a correct format.


Hi, I just started learning asp.net

i set simple application but i get this error that  "Input string was not in a correct format"

Input string was not in a correct format.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:

Line 10:     protected void Page_Load(object sender, EventArgs e)
Line 11:     {
Line 12:         decimal num1 = Decimal.Parse(txtNumber1.Text);
Line 13:         decimal num2 = Decimal.Parse(txtNumber2.Text);
Line 14:         decimal ans = num1 + num2;

How can I correct this error




Video: Converting Word Documents to PDF Format Using SharePoint Server 2010 and Word Services

Watch this visual how-to video as you learn how to programmatically convert Word documents to PDF format on the server by using Word Automation Services with SharePoint Server 2010. (Length: 6:15)

Data Conversion - string to datetime help!!!

Hi all, I need help on concatenate two fields into one then display it as datetime format as such yyyy-mm-dd hh:mm:ss AM/PM. The db is on SQL 2008 SP1. The date and time columns are on the same table and store as varchar. Date has varchar(10) and time has varchar(16). Date column shows result from query is 20100827 while the time column is either 070101.000000 or 070101. The question is how go about concatenate the two together and display in the format above in a report? How should I write my select query for this report? I am using SQL 2008 R2 BI Development Studio to design my report. Thank you. VCHS

Datetime format in textbox

Hi I'm retrieving a datetime type of data from sql table databaseMy problem is when I'm retriving it to my textbox it appear something like this -->> 1/10/1990 12:00what i want is to remove the time and appear like this only ---> 1/10/1999 How can I do this?btw I'm using c# Thanks in advance!

DateTime format from sql DataSet

Hello,This is probably a very common question.  But I have a Text Box that is being populated from the database when the page is loaded.  But is displays the time as 8/30/2010 12:00:00 AM.  I need this 8/30/2010.  In the database is it storing the date and time.  I have this which is where the text box is being populated.txt_EventDate.Text = ds.Tables[0].Rows[0]["EventDate"].ToString();How am I able to get rid of the 12:00:00 AM???Thank youvery much!!

Converting Date to String and Formating it Linq to SQL

Hello I have problem in converting date to string I am using cstr(p.tripstart) , which is returning Date as 12 Aug 2010 12:AM   I need to make formating   This is my code : Dim db As New TripsLinqDataContext Dim listtrips = (From p In db.Trips _ Group Join c In db.Countries On p.TripCountryID Equals c.TripCountryID Into countrylist = Group _ Select New With {.Tripdetails = p.TripDescription + " - " + p.TripCityList + " - " + CStr(p.tripstart) + " - " + CStr(p.TripDays), _ .Tripid = p.TripID}).ToList tripboxlist.DataSource = listtrips tripboxlist.DataTextField = "Tripdetails" tripboxlist.DataValueField = "Tripid" tripboxlist.DataBind()     Regards  

DateTime format

Hi, Can anybody tell me how to load todays date in a textbox in dd/MM/yyyy format i used this  txtFromDate.Text = DateTime.Now.ToString("dd/MM/yyyy") I am getting the output as 01-09-2010, but i want my output as 01/09/2010Hi,Can anybody tell me how to load todays date in a textbox in dd/MM/yyyy formati used this txtFromDate.Text = DateTime.Now.ToString("dd/MM/yyyy")I am getting the output as 01-09-2010, but i want my output as 01/09/2010
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend