How to pass a DateTime value to a WebMethod

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

    How to pass a DateTime value to a WebMethod

    Hi all..

    I have a WebMethod with a parameter defined as DateTime. When I call that
    webservice, I get this error:
    System.FormatEx ception: The string '07/24/2005' is not a valid AllXsd value.

    It seems that dates aren't recognized. I tried using several date formats,
    for example, dd/mm/yyyy, mm/dd/yyyy, yyyy/mm/dd, and so on, without success.

    Any help woud be greatly appreciated,

    Thanks
    Jaime
  • Allen St.Clair

    #2
    Re: How to pass a DateTime value to a WebMethod

    You can use a String (ToString) to connect them BUT if the two system
    regions are different, there maybe an error.

    So, I have my own way.

    Public Function TimeCodeMaker(B yVal Time As DateTime) As String
    Return Format(Time.Yea r Mod 100, "00") + Format(Time.Mon th, "00") +
    Format(Time.Day , "00") + Format(Time.Hou r, "00") + Format(Time.Min ute, "00")
    + Format(Time.Sec ond, "00") + Format(Time.Mil lisecond \ 100, "0")
    End Function

    Public Function TimeCodeDecoder (ByVal TimeString As String) As DateTime
    Return New DateTime(Val(Mi d(TimeString, 1, 2)), Val(Mid(TimeStr ing,
    3, 2)), Val(Mid(TimeStr ing, 5, 2)), Val(Mid(TimeStr ing, 7, 2)),
    Val(Mid(TimeStr ing, 9, 2)), Val(Mid(TimeStr ing, 11, 2)), Val(Mid(TimeStr ing,
    13, 1)) * 100)
    End Function



    "Jaime Stuardo" <JaimeStuardo@d iscussions.micr osoft.com> wrote in message
    news:02CD4CA2-8B0C-40A4-B439-BFE2EFDF1AC4@mi crosoft.com...[color=blue]
    > Hi all..
    >
    > I have a WebMethod with a parameter defined as DateTime. When I call that
    > webservice, I get this error:
    > System.FormatEx ception: The string '07/24/2005' is not a valid AllXsd
    > value.
    >
    > It seems that dates aren't recognized. I tried using several date formats,
    > for example, dd/mm/yyyy, mm/dd/yyyy, yyyy/mm/dd, and so on, without
    > success.
    >
    > Any help woud be greatly appreciated,
    >
    > Thanks
    > Jaime[/color]


    Comment

    • Jaime Stuardo

      #3
      Re: How to pass a DateTime value to a WebMethod

      Thanks Allen for answerring...

      I have finally searched the XSD specification and I have found that the date
      has to be passed using the format: CCYY-MM-DD, so I set as a requirement of
      my webservice the date to be passed using that format.

      Jaime


      "Allen St.Clair" wrote:
      [color=blue]
      > You can use a String (ToString) to connect them BUT if the two system
      > regions are different, there maybe an error.
      >
      > So, I have my own way.
      >
      > Public Function TimeCodeMaker(B yVal Time As DateTime) As String
      > Return Format(Time.Yea r Mod 100, "00") + Format(Time.Mon th, "00") +
      > Format(Time.Day , "00") + Format(Time.Hou r, "00") + Format(Time.Min ute, "00")
      > + Format(Time.Sec ond, "00") + Format(Time.Mil lisecond \ 100, "0")
      > End Function
      >
      > Public Function TimeCodeDecoder (ByVal TimeString As String) As DateTime
      > Return New DateTime(Val(Mi d(TimeString, 1, 2)), Val(Mid(TimeStr ing,
      > 3, 2)), Val(Mid(TimeStr ing, 5, 2)), Val(Mid(TimeStr ing, 7, 2)),
      > Val(Mid(TimeStr ing, 9, 2)), Val(Mid(TimeStr ing, 11, 2)), Val(Mid(TimeStr ing,
      > 13, 1)) * 100)
      > End Function
      >
      >
      >
      > "Jaime Stuardo" <JaimeStuardo@d iscussions.micr osoft.com> wrote in message
      > news:02CD4CA2-8B0C-40A4-B439-BFE2EFDF1AC4@mi crosoft.com...[color=green]
      > > Hi all..
      > >
      > > I have a WebMethod with a parameter defined as DateTime. When I call that
      > > webservice, I get this error:
      > > System.FormatEx ception: The string '07/24/2005' is not a valid AllXsd
      > > value.
      > >
      > > It seems that dates aren't recognized. I tried using several date formats,
      > > for example, dd/mm/yyyy, mm/dd/yyyy, yyyy/mm/dd, and so on, without
      > > success.
      > >
      > > Any help woud be greatly appreciated,
      > >
      > > Thanks
      > > Jaime[/color]
      >
      >
      >[/color]

      Comment

      Working...