By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,979 Members | 943 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,979 IT Pros & Developers. It's quick & easy.

String to Date Conversion

P: n/a
RN1
A TextBox displays the current date (in dd/mm/yyyy format) & time when
a user comes to a page (e.g. 15/10/2008 1:36:39 PM). To convert the
date into international format so that the remote server doesn't
generate any error, this is what I am doing:

---------------------------
Dim strSDate As String
Dim strSTime As String
Dim strStartDT As String
Dim strSDateTime As String

strSDateTime = txtSDateTime.Text

i = InStr(strSDateTime, " ")
strSDate = Left(strSDateTime, i - 1)
strSTime = (Mid(strSDateTime, i + 1, Len(strSDateTime)))

strStartDT = Year(CDate(strSDate)) & "/" & Month(CDate(strSDate)) &
"/" & Day(CDate(strSDate)) & " " & strSTime
---------------------------

The above works perfectly on my local server but on the remote server,
the last line in the above code generates the following error:

--------------------------
Conversion from string "15/10/2008" to type 'Date' is not valid.
--------------------------

What am I doing wrong?
Oct 15 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Try to pass the date to the database as a parameter of
"datetime" not as string. If you can't do this post the code segment
where you communicate with the server.

Gustavo A. Cantero
CEO - Scientia® Soluciones Informáticas
MCP - MCSD - MCTS
http://www.scientia.com.ar
http://www.programandoamedianoche.com
http://foro.scientia.com.ar

-----Mensaje original-----
De: RN1 [mailto:rn**@rediffmail.com]
Expuesto a las: Miércoles, 15 de Octubre de 2008 05:37 a.m.
Expuesto en: microsoft.public.dotnet.framework.aspnet
Conversación: String to Date Conversion
Asunto: String to Date Conversion

A TextBox displays the current date (in dd/mm/yyyy format) & time when
a user comes to a page (e.g. 15/10/2008 1:36:39 PM). To convert the
date into international format so that the remote server doesn't
generate any error, this is what I am doing:

---------------------------
Dim strSDate As String
Dim strSTime As String
Dim strStartDT As String
Dim strSDateTime As String

strSDateTime = txtSDateTime.Text

i = InStr(strSDateTime, " ")
strSDate = Left(strSDateTime, i - 1)
strSTime = (Mid(strSDateTime, i + 1, Len(strSDateTime)))

strStartDT = Year(CDate(strSDate)) & "/" & Month(CDate(strSDate)) &
"/" & Day(CDate(strSDate)) & " " & strSTime
---------------------------

The above works perfectly on my local server but on the remote server,
the last line in the above code generates the following error:

--------------------------
Conversion from string "15/10/2008" to type 'Date' is not valid.
--------------------------

What am I doing wrong?

Oct 15 '08 #2

P: n/a
CDate converts the string to a date so I'm not sure what is the purpose of
doing that (basically you want to handle the conversion yourself but this is
not the case in your code as you are suing CDate ?)

You could work on the string but IMO your best bet would be to configure the
globalization section of your web.config so that the date format is whatever
you want it to be without having any additional work to do...

See http://msdn.microsoft.com/en-us/library/hy4kkhe0.aspx and in particuler
uiCluture, Culture. Then all date/number etc operations will follow the
rules for the country you choosed...

--
Patrice

"RN1" <rn**@rediffmail.coma écrit dans le message de groupe de discussion
: 93**********************************...oglegroups.com...
A TextBox displays the current date (in dd/mm/yyyy format) & time when
a user comes to a page (e.g. 15/10/2008 1:36:39 PM). To convert the
date into international format so that the remote server doesn't
generate any error, this is what I am doing:

---------------------------
Dim strSDate As String
Dim strSTime As String
Dim strStartDT As String
Dim strSDateTime As String

strSDateTime = txtSDateTime.Text

i = InStr(strSDateTime, " ")
strSDate = Left(strSDateTime, i - 1)
strSTime = (Mid(strSDateTime, i + 1, Len(strSDateTime)))

strStartDT = Year(CDate(strSDate)) & "/" & Month(CDate(strSDate)) &
"/" & Day(CDate(strSDate)) & " " & strSTime
---------------------------

The above works perfectly on my local server but on the remote server,
the last line in the above code generates the following error:

--------------------------
Conversion from string "15/10/2008" to type 'Date' is not valid.
--------------------------

What am I doing wrong?

Oct 15 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.