String to Date Conversion

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RN1

    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.Te xt

    i = InStr(strSDateT ime, " ")
    strSDate = Left(strSDateTi me, i - 1)
    strSTime = (Mid(strSDateTi me, i + 1, Len(strSDateTim e)))

    strStartDT = Year(CDate(strS Date)) & "/" & Month(CDate(str SDate)) &
    "/" & Day(CDate(strSD ate)) & " " & 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?
  • Gustavo Cantero

    #2
    Re: String to Date Conversion

    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

    El blog de Scientia® Soluciones Informáticas



    -----Mensaje original-----
    De: RN1 [mailto:rn5a@red iffmail.com]
    Expuesto a las: Miércoles, 15 de Octubre de 2008 05:37 a.m.
    Expuesto en: microsoft.publi c.dotnet.framew ork.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.Te xt

    i = InStr(strSDateT ime, " ")
    strSDate = Left(strSDateTi me, i - 1)
    strSTime = (Mid(strSDateTi me, i + 1, Len(strSDateTim e)))

    strStartDT = Year(CDate(strS Date)) & "/" & Month(CDate(str SDate)) &
    "/" & Day(CDate(strSD ate)) & " " & 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?

    Comment

    • Patrice

      #3
      Re: String to Date Conversion

      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" <rn5a@rediffmai l.coma écrit dans le message de groupe de discussion
      : 93af5dde-1cc6-4a42-848b-e06ed84bd591...l egroups.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.Te xt
      >
      i = InStr(strSDateT ime, " ")
      strSDate = Left(strSDateTi me, i - 1)
      strSTime = (Mid(strSDateTi me, i + 1, Len(strSDateTim e)))
      >
      strStartDT = Year(CDate(strS Date)) & "/" & Month(CDate(str SDate)) &
      "/" & Day(CDate(strSD ate)) & " " & 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?

      Comment

      Working...