Results 1 to 3 of 3

Thread: [RESOLVED] date difference

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Resolved [RESOLVED] date difference

    Hi guys, I need help about date differences. See we have a link that I want to expire it after 3 months. So if the user goes to that link, it will say it's expired.

    I don't know what is the logic behind it to identify the date that saved in the database and compare it to today's date. If today's date is greater than the date in the db 3 months and more, then the link is expired. Or the year is greater than the year in the db, link expired.

  2. #2
    Lively Member
    Join Date
    Oct 2008
    Posts
    87

    Re: date difference

    what you can do is something like this:
    vb Code:
    1. Dim Today as datetime = system.datetime.now
    2. Dim ExpDate as datetime
    3. ExpDate = Today.addmonths(3)

    I just typed this out and did not check syntax... This will make the ExpDate 3 months from now

    Then you can check
    vb Code:
    1. If ExpDate > datetime.now then
    2. 'Expired
    3. else
    4. 'Do whatever you need
    5. End If
    Last edited by mjcoco01; Aug 6th, 2009 at 07:14 PM.

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: date difference

    When user visits the link, call the database, (you'll undoubtedly have the ID), get all the details that you need out. For example, if it's an article, get the title, body, keywords, published date, etc. out.

    Convert the published date to a DateTime. Then compare.
    Code:
    If DateTime.Now.AddMonths(3) >= publishedDate Then
    Response.StatusCode = 410
    Response.Status = "Expired"
    LabelMessage.Text = "This article no longer exists."
    End If
    (Something like that, don't copy paste it)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width