CDate conversion error

0
August 17, 2011

Hi

I have a textbox ticketDate.text which have value "21-10-2003".

I used the CDate function to conversion it :-  CDate(ticketDate.Text) but have

run time error.

   Cast from string "21-10-2003" to type "Date" is not valid.

Pls help

Thanks & Rgds

Heng03

12

answers

Comments See all(0)

Add comment
0
August 17, 2011

I'm sure this is the wrong way of doing this PLUS Dabas is far better at this than I and his way worked for me but

        Dim TmpStr() As String

        Dim AnsDate As Date

        TmpStr = Split(ticketDate.Text)

        AnsDate = CDate(TmpStr(1) & "/" & TmpStr(0) & "/" & TmpStr(2))

        MsgBox(AnsDate)

   - Marc

0
August 17, 2011

the error rise because the format is 2003-10-21

CDate uses standarts for datatimeformats

if you want to use your custom format you can use ticketDate.Text.ToString("

dd-mm-yyyy

");

B..G

0
August 17, 2011

Hi mmarinov

Your suggestion have syntax error.

Thanks & Rgds

Heng03

0
August 17, 2011

Hi mmarinov

Your suggestion have syntax error & compilation error.

It do not work.

Thanks & Rgds

Heng03

0
August 17, 2011

sorry, i saw it too late

i gave the code to convert datetime object to string

so to be sure that you can convert string to datetime use this

DateTime.Parse(ticketDate.

Text)

you can write it in

try

{

DateTime.Parse(ticketDate.

Text)

}

catch

{

Response.write ( "You have entered wrong date! Please try again." )

}

B..G

0
August 17, 2011

Hi heng03:

I had no problem

Created a textbox and changed its Text property to 21-10-2003

This is my code:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        MessageBox.Show(CStr(CDate

(TextBox1.

Text)))

Compiled and ran OK.

Dabas

0
August 17, 2011

use a datetimepicker control, it's easier and user friendly.

0
August 17, 2011

Hi

0
August 17, 2011

Sweet! Thanks!

   - Marc

0
August 17, 2011

heng03:

Thanks for the points!

Just out of curiosity, how does your corrected code look like?

Dabas

0
August 17, 2011

Hi everyone

I used the sample code from MarcGraff, it is the best for my situation.

My code is below.

dim TmpStr() As String

            TmpStr = Split(txtTicketDate.Text, "-")

            Try

                      TicketDate = CDate(TmpStr(1) & "-" & TmpStr(0) & "-" & TmpStr(2))

            Catch

                      validYes = False

                                errMsg &= "Error Ticket Date : Shall be dd-mm-yyyy. Please  try

                                                 again." + vbNewLine

            End Try

The reason is that, it re-substring my date from dd/mm/yyyy to mm/dd/yyyy which is

suitable for the us-EN culture date-time format ("d").

As such, the CDate(expression) will work fine. else error if format is dd/mm/yyyy.

Thanks & Rgds

Heng03

0
August 17, 2011

Hi everyone,

I increased the points from 50 to 75.

And split among 3 of you. Each 25 points.

Sorry for that.

Thanks & Rgds

Heng03

Related Questions

Stored Procedures error

Microsoft OLE DB Provider for SQL Server error '80040e14' Implicit conversion from data type datetime to int is not allowed. Use the CONVERT function to run this query. /ezservices/onlinebonds Read More

Views

57

Votes

0

Answers

4

August 16, 2011

ERROR Microsoft OLE DB Provider for ODBC Drivers (0x80040E57)

Hi,  I am using a oracle RDB casue i change from a sql database but i cant get the date to be right for the page to display. I get this error below. Error Type: Microsoft OLE DB Provider for ODBC Read More

Views

47

Votes

0

Answers

33

August 16, 2011

SSRS BI error when hiding row conversion from string ""  to type Date is not valid

I have a report that does a Cdate on two fields to convert the date to a short format: =CDate(Fields!startdate.Va lue).ToSho rtDateStri ng() I then need to hide a row using: =Iif(Fields!enddate.Value Read More

Views

42

Votes

0

Answers

3

August 17, 2011

converting Access SQL statements to SQL 2000 Statements

I am having difficulty getting a simple counter I created in ASP using Access to work when converting for SQL 2000. I recently purchased SQL 2000 and imported the counter table into sql I immediately Read More

Views

64

Votes

0

Answers

16

August 16, 2011

Why using "ms" globalization causes Cdate to fail?

Hi, I have a string of "4/22/2010" to be converted to a date using Cdate. My problem is that, using "en" (english), there is no problem on the conversion. However, when i switch it Read More

Views

8

Votes

0

Answers

3

August 17, 2011

Crustal Date format Conversion

I have a date formula called @EST (sample formula output: 11/11/2010   5:39:59PM) and I have a report column which is a Universe Object called {getdate} (sample field output: 2010-11-17 18:03:41. Read More

Views

48

Votes

0

Answers

6

August 16, 2011

ASP AJAX Calendar Extender Converting the String to Date

I want to compare the input date from the AJAX Calendar Extender with another date and I m trying to convert the input date which is a string to date Session("date") is from the other page S Read More

Views

39

Votes

0

Answers

7

August 17, 2011

ADODB.Connection?

<b>I am getting an error that says:</b> "Microsoft OLE DB Provider for ODBC Drivers error '80004005' [Microsoft][ODBC Driver Manager] Data source name not found and no default Read More

Views

74

Votes

0

Answers

10

August 16, 2011

adding last password change to vbscript (exporting Exchange 2003 mailbox statistics)

can someone please help me to add two parameters to this great vbs script of Paul Weterings? What I additionally need is > mailbox creation date > last password change date thanks for your help Read More

Views

48

Votes

0

Answers

1

August 16, 2011

Convert string parameter to datetime

I've got a problem similar to the one in http://www.experts-exchang e.com/Data base/Repor ting/ Crys talReport s/Q_231057 Read More

Views

18

Votes

0

Answers

4

August 16, 2011

This is the very first question

Hello guys! This is the first post in this site Read More

Views

2k

Votes

4

Answers

2

January 08, 2016

report values not showing up.

I have a crystal report which I pass a DataSet to using VB.NET. The report was working fine, but then I make some changes to the import query and now nothing shows up in the crystal report. Crystal do Read More

Views

1k

Votes

0

Answers

12

September 06, 2005

Event log doesn't overwrite as needed in SP4

Hello All, After upgrading from SP3 to SP4 on several Windows 2000 PRO machines everything looked fine, but from time to time applications can't write to the event log. When I try to view the appl Read More

Views

1k

Votes

0

Answers

9

May 11, 2003

"Failed to self-register XYZ.dll"

Hi there, I wrote a OLE-automation-server DLL in VB4.0. I use Installshield Express to install it as part of my program on the target computers. Now on some computers I get the message "Failed to Read More

Views

5k

Votes

0

Answers

2

November 08, 1998

Please help understand these notes on image processing

Can someone please help me understand these lecture notes... On the right of the page; What does "normalised by one notion of the area of a pixel" mean? On the first formula for A, Is that a Read More

Views

1k

Votes

0

Answers

3

February 05, 2009

Can someone please explain this paragram on the chain rule in image processing

Please see the screenshot, How is 3133030 got from 10103322? Read More

Views

1k

Votes

0

Answers

1

January 05, 2009

AD on 2003

We have created an AD Domain on Windows 2000 Server with no problems. We just created an AD Domain on Windows 2003 and we're getting some weird problems. Both of these domains are behind firewalls Read More

Views

1k

Votes

0

Answers

15

May 11, 2003

ADDT ASP Upload Error " Type mismatch: 'tNG_isFileInsideBaseFolder' "

I am trying to create a simple insert record and upload image function on an ASP page built using Adobe Dreamweaver Developer Toolkit. I have done this many times before with no problem, however, i ha Read More

Views

1k

Votes

0

Answers

0

November 02, 2008

MYSQL Select query with custom ORDER BY

Hi, is it possible to customize the order of the returned rows in mysql? Example: I have a Table with a column "name", now I want to have all entries ordered by name, but I want the entries Read More

Views

1k

Votes

0

Answers

5

July 02, 2010

Folder Redirection in Server 2003

We have a Windows Server 2003 Standard Ed. Is there a way to redirect the users my documents to a folder that has already been created on the server? Read More

Views

1k

Votes

0

Answers

2

July 05, 2007