473,651 Members | 2,580 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String to date

I've tried several different ways all with the same reults. Invalid date

Dim ddate As String

ddate = "11/22/2004"

Dim TryToConvert As Date = Date.Parse(ddat e)

Dim TryToConvert2 As Date = Convert.ToDateT ime(ddate)

MsgBox(CDate(dd ate) & TryToConvert & " " & TryToConvert2)
Nov 21 '05 #1
18 2122
"David Gacek" <so*****@hotmai l.com> wrote in news:uTyL3#F0EH A.3468
@TK2MSFTNGP14.p hx.gbl:
I've tried several different ways all with the same reults. Invalid date

Dim ddate As String

ddate = "11/22/2004"

Dim TryToConvert As Date = Date.Parse(ddat e)

Dim TryToConvert2 As Date = Convert.ToDateT ime(ddate)

MsgBox(CDate(dd ate) & TryToConvert & " " & TryToConvert2)

Try TryToConvert = CDate("11/22/2004") That should work.

http://msdn.microsoft.com/library/de...l=/library/en-
us/vblr7/html/vagrptypeconver sion.asp
--
Lucas Tam (RE********@rog ers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #2
Lucas,

For people who are Googling this newsgroup and find your sample,
Try TryToConvert = CDate("11/22/2004") That should work

Try TryToConvert = CDate("11/22/2004") That should work in the USA

A better sample can be
\\\
Dim mydate As String = New Date(2004, 11, 22).ToString
Dim TryToConvert As Date = CDate(mydate)
///

The last just an idea,

Cor
Nov 21 '05 #3
How about DateTime.ParseE xact() ?

"David Gacek" <so*****@hotmai l.com> wrote in message
news:uT******** ******@TK2MSFTN GP14.phx.gbl...
I've tried several different ways all with the same reults. Invalid date

Dim ddate As String

ddate = "11/22/2004"

Dim TryToConvert As Date = Date.Parse(ddat e)

Dim TryToConvert2 As Date = Convert.ToDateT ime(ddate)

MsgBox(CDate(dd ate) & TryToConvert & " " & TryToConvert2)

Nov 21 '05 #4
Can you please provide me with a working example
as you can see this code didn't work either
Dim ddate As String

ddate = "11/22/2004"

Dim TryToConvert As Date

MsgBox(TryToCon vert = CDate("11/22/2004"))

"Lucas Tam" <RE********@rog ers.com> wrote in message
news:Xn******** *************** ****@140.99.99. 130...
"David Gacek" <so*****@hotmai l.com> wrote in news:uTyL3#F0EH A.3468
@TK2MSFTNGP14.p hx.gbl:
I've tried several different ways all with the same reults. Invalid date

Dim ddate As String

ddate = "11/22/2004"

Dim TryToConvert As Date = Date.Parse(ddat e)

Dim TryToConvert2 As Date = Convert.ToDateT ime(ddate)

MsgBox(CDate(dd ate) & TryToConvert & " " & TryToConvert2)

Try TryToConvert = CDate("11/22/2004") That should work.

http://msdn.microsoft.com/library/de...l=/library/en-
us/vblr7/html/vagrptypeconver sion.asp
--
Lucas Tam (RE********@rog ers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 21 '05 #5
Shiva,
How about DateTime.ParseE xact() ?
That you can use with your sample:

When it is a field from a textbox, than you have to be absolute sure that
your program only is used in a USA datetime format zone, by instance for
Canada that is not sure.

When it is in a document or webpage when you are 100% sure that it is
returned from the zone above.

I hope this helps?

Cor

"Shiva" <sh******@onlin e.excite.com>
How about DateTime.ParseE xact() ?

"David Gacek" <so*****@hotmai l.com> wrote in message
news:uT******** ******@TK2MSFTN GP14.phx.gbl...
I've tried several different ways all with the same reults. Invalid date

Dim ddate As String

ddate = "11/22/2004"

Dim TryToConvert As Date = Date.Parse(ddat e)

Dim TryToConvert2 As Date = Convert.ToDateT ime(ddate)

MsgBox(CDate(dd ate) & TryToConvert & " " & TryToConvert2)

Nov 21 '05 #6
DateTime.ParseE xac can i use that in any time zone ? and how can i use it to
return the date in mmddyyyy format Month/Day/Year ?



"Cor Ligthert" <no************ @planet.nl> wrote in message
news:O6******** ******@tk2msftn gp13.phx.gbl...
Shiva,
How about DateTime.ParseE xact() ?


That you can use with your sample:

When it is a field from a textbox, than you have to be absolute sure that
your program only is used in a USA datetime format zone, by instance for
Canada that is not sure.

When it is in a document or webpage when you are 100% sure that it is
returned from the zone above.

I hope this helps?

Cor

"Shiva" <sh******@onlin e.excite.com>
How about DateTime.ParseE xact() ?

"David Gacek" <so*****@hotmai l.com> wrote in message
news:uT******** ******@TK2MSFTN GP14.phx.gbl...
I've tried several different ways all with the same reults. Invalid date

Dim ddate As String

ddate = "11/22/2004"

Dim TryToConvert As Date = Date.Parse(ddat e)

Dim TryToConvert2 As Date = Convert.ToDateT ime(ddate)

MsgBox(CDate(dd ate) & TryToConvert & " " & TryToConvert2)


Nov 21 '05 #7
"David Gacek" <so*****@hotmai l.com> wrote in
news:uV******** ******@TK2MSFTN GP11.phx.gbl:
Can you please provide me with a working example
as you can see this code didn't work either
Dim ddate As String

ddate = "11/22/2004"

Dim TryToConvert As Date

MsgBox(TryToCon vert = CDate("11/22/2004"))

Works A-OK on my side...
Dim DateString As String = "11/22/2004"
Dim TestDate As Date = CDate(DateStrin g)
MsgBox(TestDate )

I don't know what's wrong with your development environment. What error
did you get?

Are you in the UK? Possibly CDate is trying to convert your US Date into
a UK date - which would make it an invalid date.

--
Lucas Tam (RE********@rog ers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #8
ParseExact() basically lets you specify the date/time format to expect when
parsing the string value.

For example, DateTime.ParseE xact ("2004/11/22", "yyyy/MM/dd", null) will get
you a DateTime value with correct date value interpretations . And
DateTime.ParseE xact ("2004/11/22", "yyyy/MM/dd", null).ToString
("MM/dd/yyyy") returns the value in the specified format - "11/22/2004".

Hope this is what you are looking for.

"David Gacek" <so*****@hotmai l.com> wrote in message
news:e1******** ******@TK2MSFTN GP09.phx.gbl...
DateTime.ParseE xac can i use that in any time zone ? and how can i use it to
return the date in mmddyyyy format Month/Day/Year ?



"Cor Ligthert" <no************ @planet.nl> wrote in message
news:O6******** ******@tk2msftn gp13.phx.gbl...
Shiva,
How about DateTime.ParseE xact() ?


That you can use with your sample:

When it is a field from a textbox, than you have to be absolute sure that
your program only is used in a USA datetime format zone, by instance for
Canada that is not sure.

When it is in a document or webpage when you are 100% sure that it is
returned from the zone above.

I hope this helps?

Cor

"Shiva" <sh******@onlin e.excite.com>
How about DateTime.ParseE xact() ?

"David Gacek" <so*****@hotmai l.com> wrote in message
news:uT******** ******@TK2MSFTN GP14.phx.gbl...
I've tried several different ways all with the same reults. Invalid date

Dim ddate As String

ddate = "11/22/2004"

Dim TryToConvert As Date = Date.Parse(ddat e)

Dim TryToConvert2 As Date = Convert.ToDateT ime(ddate)

MsgBox(CDate(dd ate) & TryToConvert & " " & TryToConvert2)



Nov 21 '05 #9
Cor,

DateTime.ParseE xact() lets you specifiy the format that the date/time string
value is exepcted to be in. If you, for example, have the string as
2004/10/20, you can tell DateTime to interpret it as "yyyy/MM/dd" and you
get the correct day, month and year values.

Of course, an exception is raised if the specified string value is not as
per the given format.

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:O6******** ******@tk2msftn gp13.phx.gbl...
Shiva,
How about DateTime.ParseE xact() ?
That you can use with your sample:

When it is a field from a textbox, than you have to be absolute sure that
your program only is used in a USA datetime format zone, by instance for
Canada that is not sure.

When it is in a document or webpage when you are 100% sure that it is
returned from the zone above.

I hope this helps?

Cor

"Shiva" <sh******@onlin e.excite.com>
How about DateTime.ParseE xact() ?

"David Gacek" <so*****@hotmai l.com> wrote in message
news:uT******** ******@TK2MSFTN GP14.phx.gbl...
I've tried several different ways all with the same reults. Invalid date

Dim ddate As String

ddate = "11/22/2004"

Dim TryToConvert As Date = Date.Parse(ddat e)

Dim TryToConvert2 As Date = Convert.ToDateT ime(ddate)

MsgBox(CDate(dd ate) & TryToConvert & " " & TryToConvert2)


Nov 21 '05 #10

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

Similar topics

2
39797
by: Hector A | last post by:
Hi I'm trying to convert a string that already looks like a date to a date that I can use when I pass it from java to the database. I receive the date in format yyyy-mm-dd and I need it to be a date variable in 'mm/dd/yyyy' or 'm/dd/yyyy' format. My code is shown below. Any suggestions? code: String sailYear = (String)sail_date.toString().substring(0,4);
3
3726
by: praba kar | last post by:
Dear All, I have doubt regarding date string to time conversion function. In Python I cannot find flexible date string conversion function like php strtotime. I try to use following type function 1) parsedate function failed if a date string like below format "16-MAY-2005 01:26" 2)parsedate_tz function also failed if a date string
6
1651
by: Thomas Scheiderich | last post by:
I have the following page as test.aspx: *************************************************** <html> <head> <title>Hello and Welcome Page</title> </head> <body> <center> <% Dim CurrentDate As String
16
10476
by: PK9 | last post by:
I have a string variable that holds the equivalent of a DateTime value. I pulled this datetime from the database and I want to strip off the time portion before displaying to the user. I am using C# eg. - String variable "strMyDate" holds the value "1/1/2005 12:00:00 AM" from the database. - I do not care about the time portion, I only want "1/1/2005" for display.
3
3016
by: carl.barrett | last post by:
Hi, I have a number of buttons on a form which run mailmerges. Next to each button is a text box/control that the user enters a date into when the letter was created/merged. When the user presses the button it calls a function called LetterMerge to carry out a mail merge. Here is the on click property for one of the buttons: Private Sub cmdConsultationEWO_Click()
50
4922
by: z. f. | last post by:
HI, i have string in format dd/mm/yyyyy hh:mm:ss and giving this as an input to DateTime.Parse gives a string was not recognized as a valid date time format string error. how do i make the parse method to accept formating that i need. if i do console.writeLine DateTime.Now.ToString it gives the format: YYYY-MM-DD HH:MM:SS TIA, Z.
22
4118
by: Simon Says | last post by:
Dear all, I have the following: dim tmpString as String = "11/21/2004 07:55:33" dim tmpDate as Date = CDate(tmpString) But I keep getting <cast from string "11/21/2004 07:55:33" to type 'Date' is not valid.> Is there anything that I did wrong?
2
2945
by: Kun | last post by:
I have an html form that takes dates and inserts them into a mysql file. Currently, users have to type in dates in the yyyy-mm-dd format. As of now, this process works with the sql. However, I would like to make this process easier by: 1) providing drop down menus for year, month, and date respectively. in a failed attempt, i tried made 3 drop down lists (dateyear, datemonth, dateday) respectively and then used string interpolation...
1
2122
by: jwf | last post by:
This question continues on from a previous post "DATE to string" but I think it deserves a new thread. In my previous post I was trying to convert a DATE to string in a NON MFC C++ application which (with a little help) was achieved with the following code: ****************** // Variables DATE MailDateTime;
5
2314
by: AMP | last post by:
Hello, I want to add some variables to a string and this isnt working. textBox1.Text="'BSL version='+ bslVerHi+ bslVerLo"; What am I doing wrong? Thanks Mike
0
8349
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5609
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4143
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4281
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
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 we have to send another system
1
1906
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.