asp date function for past dates only

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fran7
    New Member
    • Jul 2006
    • 229

    asp date function for past dates only

    Hi, I wonder if anyone can help.
    I have a query like this

    Code:
    <%
    If  datediff("d", [PDnewsfield],  now())  < 21  Then
    %> 
    <a target=_blank title="blog" href="news</a>
    <%
    Else
    %> 
    <%
    End If
    %>
    I am working with an access 2000 database and the date function is written in general format like 19/08/2009 22:27:20

    I have an input field with a date picker so a user in their control panel can select a date in the future and in the past for a news event. I want news event to show on the website from the date they choose and for 21 days after that date only. This code I have above is fine in another context but if a user picks a date in the future it will show it when I dont want it to. If anyone can point me to the function I would need that would be great.
    Thanks
    Richard
  • fran7
    New Member
    • Jul 2006
    • 229

    #2
    Hi, I am sorry I think I havent explained well. I need an if clause to say

    if date in field "PDnewsfiel d" = todays date
    then
    show content "PDnewsfieldcon tent"
    and for only 21 days after the date.

    Thanks for any advice
    Richard

    Comment

    • jhardman
      Recognized Expert Specialist
      • Jan 2007
      • 3405

      #3
      I'm not 100% sure I follow you, but I think you just need to replace "now()" with an expression for the date in the future you wanted to look at. Does this make sense?

      Jared

      Comment

      • fran7
        New Member
        • Jul 2006
        • 229

        #4
        Hi Jared, I have a news and a date field in my database. I need the news to appear on the webpage only when the date in the date field = now()
        and to only appear for 21 days after the date in the date field.
        I have looked at dateadd and datedif functions. This gets me the news but I need to show for only 21 days before it doesnt show anymore. I dont know if thats any clearer or you can suggest which combinations of functions I would need.
        <%
        If (Now) = RS("date") Then
        %>
        display news
        <%
        Else
        %>
        <%
        End If
        %>
        Thanks
        Richard

        Comment

        • fran7
          New Member
          • Jul 2006
          • 229

          #5
          Asp show date dependant content

          Hi, I think I worked it out. This seems to do the trick.
          <%
          strDate = Date()
          If (Date) <= RS("mynewsdate" ) and DateDiff("d", strDate, rs("mynewsdate" ) ) < 21 then
          %>
          news
          <%
          Else
          %>
          <%
          End If
          %>
          Thanks for your advice
          Richard

          Comment

          • fran7
            New Member
            • Jul 2006
            • 229

            #6
            Hi, Had to get back. It works fine but now I have a problem with the database and inputting the date. I changed the field to a date and time field and it threw up problems. It works fine if there is a date to submit but if left blank it throws up type mismatch. I have the date field as "not required" so not sure why this might be. Tried many tinkerings to no avail.

            The form field is like this
            Code:
            Response.Write "<input type=""text"" name=""PDimageninemedium"" value=""" & objGetPersonalProfileOnEdit("PDimageninemedium") & """ size=""30"" maxlength=""30"">"
            and I just wonder if I need to add something to show its a date being entered as 1. when I had the database field as a text field it worked fine.
            2. if I cut the time of the end of the date its fine but if I cut some of the date itself it throws up the same error again.

            Thank makes me think its a database thing but the field is set at not required so bit at a loss.
            Any ideas would be great
            Thanks
            Richard

            Comment

            • jhardman
              Recognized Expert Specialist
              • Jan 2007
              • 3405

              #7
              hmm. Never had that problem before, sounds like it's db-specific. You said you are using access? I'll ask an access expert to weigh in.

              Jared

              Comment

              • fran7
                New Member
                • Jul 2006
                • 229

                #8
                Dear jared, Yes I looked around and it seems that entering null in a date field throws up errors. I worked around it by making it a required field at the user end so they dont get to see the error as they have to input a date regardless. It seemed to complicated for me to make the code accept null values as there seemed to be solutions in that respect.
                Thanks for your help
                Richard

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32645

                  #9
                  Can you say what the Required property is set to for that field in your database?

                  If it is set to Yes then that may well explain your difficulty.

                  Comment

                  • Frinavale
                    Recognized Expert Expert
                    • Oct 2006
                    • 9749

                    #10
                    I don't know the answer to your problem but I know what's happening.

                    Null in your code is not MS Access's "null".

                    .NET has figured out a way to get around this.

                    In .NET there is the DBNull Object. This Object can be used to determine if NULL was returned by the database it's connecting to (whether it be MS Access, MySQL, or MS SQL). You can also use this object to supply NULL to the database you're connecting to.

                    (In .NET you use the DBNull.Value to supply "null" to the database that you're using. )


                    You need to find a way to supply an "MS Access" null to the database.

                    -Frinny

                    Comment

                    • keithfer15
                      New Member
                      • Aug 2009
                      • 1

                      #11
                      there are many many places whee you can study .NET, i am a software programmer, i do JAVA
                      you can try, code project or msdn to get the codes sorted
                      Last edited by NeoPa; Aug 23 '09, 06:12 PM. Reason: Illegal Signature removed

                      Comment

                      • fran7
                        New Member
                        • Jul 2006
                        • 229

                        #12
                        Thanks guys, I have adapted already written code so I think frinny you are right, I will have to look into that further.
                        Thanks a lot for all your advice.
                        Richard

                        Comment

                        Working...