Date Formatting problem

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

    Date Formatting problem

    Hi,

    I have an ASPX page with a textbox where the user enters a
    date.

    I have a variable of tyope date that I populate from teh
    form
    d

    dtMyDate = Request.Form("t xMyDate")

    I then call a function that formats my date.

    Public Function FormatDate(ByVa l dtMyDate as date) as Date

    FormatDate = Format(dtMyDate , "mm/dd/yyyy")
    End Function


    If I pass in the date 01/01/2003, it formats it as
    00/01/2003.

    Any ideas why this is.

    Thanks,
    Kerri.


  • Steven Campbell

    #2
    Re: Date Formatting problem

    Kerri wrote:
    [color=blue]
    > Public Function FormatDate(ByVa l dtMyDate as date) as Date
    >
    > FormatDate = Format(dtMyDate , "mm/dd/yyyy")
    > End Function
    >
    >
    > If I pass in the date 01/01/2003, it formats it as
    > 00/01/2003.
    >
    > Any ideas why this is.
    >[/color]

    Your function does not really do any formatting, since it returns a
    "Date" datatype, which is not formatted. If it returned a string, then
    it should work.

    I also thought the correct syntax was:
    return Format(dtMyDate , "mm/dd/yyyy")

    If it compiles, I guess its fine, but I like the "return" syntax better
    than the old VB6 syntax that you are using, mainly because it is easier
    to read, and makes renaming the function much simpler.

    Comment

    • yop

      #3
      Date Formatting problem

      Hello

      I saw this and found it works perfect.

      Dim rightNow As DateTime = DateTime.Now
      Dim sDateTime As String

      sDateTime = rightNow.ToStri ng("MM/dd/yyyy")


      [color=blue]
      >-----Original Message-----
      >Hi,
      >
      >I have an ASPX page with a textbox where the user enters[/color]
      a[color=blue]
      >date.
      >
      >I have a variable of tyope date that I populate from teh
      >form
      >d
      >
      >dtMyDate = Request.Form("t xMyDate")
      >
      >I then call a function that formats my date.
      >
      >Public Function FormatDate(ByVa l dtMyDate as date) as[/color]
      Date[color=blue]
      >
      > FormatDate = Format(dtMyDate , "mm/dd/yyyy")
      >End Function
      >
      >
      >If I pass in the date 01/01/2003, it formats it as
      >00/01/2003.
      >
      >Any ideas why this is.
      >
      >Thanks,
      >Kerri.
      >
      >
      >.
      >[/color]

      Comment

      • Jerry III

        #4
        Re: Date Formatting problem

        "mm" in date format string means minute, not month. Month is what yop used,
        MM.

        Jerry
        [color=blue][color=green]
        > >-----Original Message-----
        > >Hi,
        > >
        > >I have an ASPX page with a textbox where the user enters[/color]
        > a[color=green]
        > >date.
        > >
        > >I have a variable of tyope date that I populate from teh
        > >form
        > >d
        > >
        > >dtMyDate = Request.Form("t xMyDate")
        > >
        > >I then call a function that formats my date.
        > >
        > >Public Function FormatDate(ByVa l dtMyDate as date) as[/color]
        > Date[color=green]
        > >
        > > FormatDate = Format(dtMyDate , "mm/dd/yyyy")
        > >End Function
        > >
        > >
        > >If I pass in the date 01/01/2003, it formats it as
        > >00/01/2003.
        > >
        > >Any ideas why this is.
        > >
        > >Thanks,
        > >Kerri.
        > >
        > >
        > >.
        > >[/color][/color]


        Comment

        Working...