Dealing with Dates?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Dealing with Dates?

  1. #1
    Jeff Guest

    Dealing with Dates?


    I have a database web app that both displays
    and allows entry/edit of date fields in the
    format of mm/dd/yyyy. My app uses SQL Server 7
    as the back end, datetime fields.

    Dealing with both invalid/and missing dates
    has become a problem. I beleive this task should
    be divided up into two area's:
    1) Client Side Validation/Display
    2) Server Side update

    But am not sure exactly how....


    Assign initial value for display with:

    xProtectFr = objRst1("ProtectFr")

    Display date with:

    <INPUT name="ProtectFr" value=" <%= FormatDateTime(xProtectFr,vbShortDate)
    %>" size=10 width="10">



    Not really sure how to handle update because:
    What if date field value has been removed/blank?
    What if invalid ie 1/97? ...
    I would want to warn user date invalid in this case.

    If IsDate(Request.Form("ProtectFr")) Then
    objRst1("ProtectFr") = Request.Form("ProtectFr")
    Else
    objRst1("ProtectFr") = What here ?
    End If

    objRst1.Update

    Any ideas... samples... ?



  2. #2
    Michael \(michka\) Kaplan Guest

    Re: Dealing with Dates?

    You should fail the update if the returned value cannot be coerced into a
    date... .seems simple enough!

    --
    MichKa

    random junk of dubious value at the multilingual
    http://www.trigeminal.com/ and a new book on
    i18N in VB at http://www.trigeminal.com/michka.asp

    "Jeff" <jeffm@earthlink.net> wrote in message
    news:398601b6$1@news.devx.com...
    >
    > I have a database web app that both displays
    > and allows entry/edit of date fields in the
    > format of mm/dd/yyyy. My app uses SQL Server 7
    > as the back end, datetime fields.
    >
    > Dealing with both invalid/and missing dates
    > has become a problem. I beleive this task should
    > be divided up into two area's:
    > 1) Client Side Validation/Display
    > 2) Server Side update
    >
    > But am not sure exactly how....
    >
    >
    > Assign initial value for display with:
    >
    > xProtectFr = objRst1("ProtectFr")
    >
    > Display date with:
    >
    > <INPUT name="ProtectFr" value=" <%= FormatDateTime(xProtectFr,vbShortDate)
    > %>" size=10 width="10">
    >
    >
    >
    > Not really sure how to handle update because:
    > What if date field value has been removed/blank?
    > What if invalid ie 1/97? ...
    > I would want to warn user date invalid in this case.
    >
    > If IsDate(Request.Form("ProtectFr")) Then
    > objRst1("ProtectFr") = Request.Form("ProtectFr")
    > Else
    > objRst1("ProtectFr") = What here ?
    > End If
    >
    > objRst1.Update
    >
    > Any ideas... samples... ?
    >
    >




  3. #3
    mcdba Guest

    Re: Dealing with Dates?

    Jeff,

    <%
    If IsDate(Request.Form("ProtectFr")) Then
    objRst1("ProtectFr") = Request.Form("ProtectFr")
    Else
    objRst1("ProtectFr") = What here ?
    End If
    %>

    when i come to this situation, i will put a null value into this field
    (make sure your field is set to allow null value, use Enterprise Manager )




  4. #4
    Jeff Guest

    Re: Dealing with Dates?


    mcdba,

    Yes, I thought the same thing....at first but then ran into
    yet another problem....

    So Ok, now we have a Null saved....

    Next time I access this record to display...

    If IsDate(objRst1("ProtectFr")) Then
    xProtectFr = objRst1("ProtectFr")
    Else
    xProtectFr = What Now? ... Cdate(?)
    End If

    Because if xProtectFr is not a date....
    this line will crap out:

    I edit with this:

    <INPUT name="ProtectFr" value=" <%= FormatDateTime(xProtectFr,vbShortDate)
    %>" size=10 width="10">


    And display with this:

    <INPUT name="ProtectFr" value=" <%= FormatDateTime(xProtectFr,vbShortDate)
    %>" size=10 width="10" DISABLED>

    I then end up with multiple edit/display lines too?

    Jeff






    "mcdba" <z08@hotmail.com> wrote:
    >Jeff,
    >
    ><%
    >If IsDate(Request.Form("ProtectFr")) Then
    > objRst1("ProtectFr") = Request.Form("ProtectFr")
    >Else
    > objRst1("ProtectFr") = What here ?
    >End If
    >%>
    >
    >when i come to this situation, i will put a null value into this field
    >(make sure your field is set to allow null value, use Enterprise Manager

    )
    >
    >
    >



  5. #5
    Jeff Guest

    Re: Dealing with Dates?



    mcdba,

    The change made at "<- This works but.." below prevents crashing but does
    not really address
    two problems.....

    1. SQL Server displays 12/30/1899 and I would prefer to display " / /
    " without the " to show
    user date entry is expected.

    2. If user enters invalid date or date out of range, I would want to display
    warning message
    of some kind.


    I know this is not simple...do you know where I can find example of how this
    is done? I'm a Foxpro
    and Visual Basic programmer and find my loss of control disturbing.... :-)

    Thanks

    Jeff


    >
    >mcdba,
    >
    >Yes, I thought the same thing....at first but then ran into
    >yet another problem....
    >
    >So Ok, now we have a Null saved....
    >
    >Next time I access this record to display...
    >
    >If IsDate(objRst1("ProtectFr")) Then
    > xProtectFr = objRst1("ProtectFr")
    >Else
    > xProtectFr = FormatDateTime(xProtectFr,vbShortDate) <- This works

    but...
    >End If
    >
    >Because if xProtectFr is not a date....
    >this line will crap out:
    >
    >I edit with this:
    >
    ><INPUT name="ProtectFr" value=" <%= FormatDateTime(xProtectFr,vbShortDate)
    >%>" size=10 width="10">
    >
    >
    >And display with this:
    >
    ><INPUT name="ProtectFr" value=" <%= FormatDateTime(xProtectFr,vbShortDate)
    >%>" size=10 width="10" DISABLED>
    >
    >I then end up with multiple edit/display lines too?
    >
    >Jeff
    >
    >
    >
    >
    >
    >
    >"mcdba" <z08@hotmail.com> wrote:
    >>Jeff,
    >>
    >><%
    >>If IsDate(Request.Form("ProtectFr")) Then
    >> objRst1("ProtectFr") = Request.Form("ProtectFr")
    >>Else
    >> objRst1("ProtectFr") = What here ?
    >>End If
    >>%>
    >>
    >>when i come to this situation, i will put a null value into this field
    >>(make sure your field is set to allow null value, use Enterprise Manager

    >)
    >>
    >>
    >>

    >



  6. #6
    Craig Guest

    Re: Dealing with Dates?

    Checkout http://www.javascript.com There's a sample JavaScript there that
    does a lot of error checking on the date format (even checks number of days
    in the month).

    "Jeff" <jeffm@earthlink.net> wrote in message
    news:398734bb$1@news.devx.com...
    >
    >
    > mcdba,
    >
    > The change made at "<- This works but.." below prevents crashing but does
    > not really address
    > two problems.....
    >
    > 1. SQL Server displays 12/30/1899 and I would prefer to display " / /
    > " without the " to show
    > user date entry is expected.
    >
    > 2. If user enters invalid date or date out of range, I would want to

    display
    > warning message
    > of some kind.
    >
    >
    > I know this is not simple...do you know where I can find example of how

    this
    > is done? I'm a Foxpro
    > and Visual Basic programmer and find my loss of control disturbing.... :-)
    >
    > Thanks
    >
    > Jeff
    >
    >
    > >
    > >mcdba,
    > >
    > >Yes, I thought the same thing....at first but then ran into
    > >yet another problem....
    > >
    > >So Ok, now we have a Null saved....
    > >
    > >Next time I access this record to display...
    > >
    > >If IsDate(objRst1("ProtectFr")) Then
    > > xProtectFr = objRst1("ProtectFr")
    > >Else
    > > xProtectFr = FormatDateTime(xProtectFr,vbShortDate) <- This

    works
    > but...
    > >End If
    > >
    > >Because if xProtectFr is not a date....
    > >this line will crap out:
    > >
    > >I edit with this:
    > >
    > ><INPUT name="ProtectFr" value=" <%=

    FormatDateTime(xProtectFr,vbShortDate)
    > >%>" size=10 width="10">
    > >
    > >
    > >And display with this:
    > >
    > ><INPUT name="ProtectFr" value=" <%=

    FormatDateTime(xProtectFr,vbShortDate)
    > >%>" size=10 width="10" DISABLED>
    > >
    > >I then end up with multiple edit/display lines too?
    > >
    > >Jeff
    > >
    > >
    > >
    > >
    > >
    > >
    > >"mcdba" <z08@hotmail.com> wrote:
    > >>Jeff,
    > >>
    > >><%
    > >>If IsDate(Request.Form("ProtectFr")) Then
    > >> objRst1("ProtectFr") = Request.Form("ProtectFr")
    > >>Else
    > >> objRst1("ProtectFr") = What here ?
    > >>End If
    > >>%>
    > >>
    > >>when i come to this situation, i will put a null value into this field
    > >>(make sure your field is set to allow null value, use Enterprise Manager

    > >)
    > >>
    > >>
    > >>

    > >

    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center