473,506 Members | 17,309 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert Date to appropriate format

RP
I am using SQL Server 2005 as backend. I have a Text Box that accepts
Date in the format dd-MM-yyyy. But when I attempt to insert a record,
an error is displayed: Cannot convert char to DateTime ....

Actually, when the text box has entry like 22-10-2005, it considers 22
as month whereas it is DD. How to convert the Text Box value to an
acceptable format.

I tried: DateTime.parse(txtDOB.Text,"dd-MM-yyyy")

It gives error.

Aug 16 '07 #1
4 2476
RP wrote:
I am using SQL Server 2005 as backend. I have a Text Box that accepts
Date in the format dd-MM-yyyy. But when I attempt to insert a record,
an error is displayed: Cannot convert char to DateTime ....

Actually, when the text box has entry like 22-10-2005, it considers 22
as month whereas it is DD. How to convert the Text Box value to an
acceptable format.

I tried: DateTime.parse(txtDOB.Text,"dd-MM-yyyy")

It gives error.
There is no overload of DateTime.Parse that takes a date and a format.
Use ParseExact instead. Ex:

DateTime dt = DateTime.ParseExact(txtDOB.text, "dd-MM-yyyy",
System.Globalization.DateTimeFormatInfo.CurrentInf o);
--
Tom Porterfield
Aug 16 '07 #2
RP
Tried as below. But still errors.

On Aug 16, 11:28 pm, Tom Porterfield <tppor...@mvps.orgwrote:
There is no overload of DateTime.Parse that takes a date and a format.
Use ParseExact instead. Ex:

DateTime dt = DateTime.ParseExact(txtDOB.text, "dd-MM-yyyy",
System.Globalization.DateTimeFormatInfo.CurrentInf o);

Aug 17 '07 #3
what's wrong with?

string inputSplit = txtDOB.Text.Split(new char[] { '-' });
// dd-MM-yyyy to yyyy-MM-dd
DateTime newDate = new DateTime(
Convert.ToInt16(inputSplit[2]),
Convert.ToInt16(inputSplit[1]),
Convert.ToInt16(inputSplit[0]));

Regards,
Joachim
Aug 20 '07 #4
On Thu, 16 Aug 2007 17:40:24 -0000, RP <rp*********@gmail.comwrote:
>I am using SQL Server 2005 as backend. I have a Text Box that accepts
Date in the format dd-MM-yyyy. But when I attempt to insert a record,
an error is displayed: Cannot convert char to DateTime ....

Actually, when the text box has entry like 22-10-2005, it considers 22
as month whereas it is DD. How to convert the Text Box value to an
acceptable format.

I tried: DateTime.parse(txtDOB.Text,"dd-MM-yyyy")

It gives error.
Hi RP,

You could eliminate 99% of your headaches by using more appropriate
controls like a datepicker or a calendar. The reason being you do not
need to write any validation code and your date serialization will be
independent of gotchas like client pc's regional settings

--
http://bytes.thinkersroom.com
Aug 20 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5342
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
1
601
by: Mike P | last post by:
I've been using this code to get the date in the format dd/mm/yyyy with Culture="en-GB": DateFrom = Convert.ToDateTime(DateFrom.ToString("d")); Now I need to put the date in US format, so I've...
2
5068
by: Franck | last post by:
Hi, 'm gettin mad about date conversion. Here is the point. Got and add-in for Excel which call functions from a web service (on a remote server) The remote server has regional settings...
1
4577
by: abcabcabc | last post by:
I write an application which can let user define own date format to input, How to convert the date string to date value with end-user defined date format? Example, User Defined Date Format as...
11
10540
by: shsandeep | last post by:
I used the following query to retrieve the date in dd-mon-yyyy format. db2 => SELECT RTRIM(CHAR(DAY(COVG_TYP_STRT_DT))) || '-' || RTRIM(MONTHNAME(COVG_TYP_STRT_DT)) || '-' ||...
16
11879
by: Mik | last post by:
I apologise if this post seems a little basic, but I am a newbie and have NO access knowledge. I have downloaded the Accounts Ledger from the Microsoft Website. It allows the user to review a...
2
16765
by: thewilldog | last post by:
Hello, I've reviewed the archives here to address the issue, but I'm still running into problems. I've got a table field populated with the record date in text "YYYYMMDD" To convert it into a...
4
30245
by: Ashraf Ansari | last post by:
Hi, How Can I convert MM/dd/yyyy format into dd/MM/yyyy and the date which is converted into dd/MM/yyyy should be in DateTime format. I do not want to store it as a string. Please help ...
4
4508
by: thomasc1020 | last post by:
This is regarding VB.NET 2003. Variable 'Date' is a string and it contains date information in this format: "DEC/05/2007". Now I am trying to convert the format as "2007-12-05". Is it...
0
7308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.