Forum Moderators: open

Message Too Old, No Replies

Date manipulation: is date X older than date Y?

compare current date with date of entry

         

Darkelve

10:34 am on May 10, 2007 (gmt 0)

10+ Year Member



I have to create a webpage table, which shows some text in a table cell, depending on whether the date is older or newer than the date of entry.

That is, I'm using a database table field where you can enter dates in format DD/MM/YYYY. One date (or no date) for each Point of Sale.

Now what has to happen is that the text should ONLY appear for those items which
- A: have a date (older POS will have an empty date field)
- B: have been entered less than three months before the current date (on the server)

So I was thinking to use an If construct, similar to:

IF
less than three months have passed between the date of entry (in the database)
THEN
show the text
Else
show nothing

However, I don't know a method I could use for manipulating these dates and calculating how many months (or: 90 days, does not need to be so strict) are between the two dates. Is there something that can convert a date to a number or do a comparison so I can compare and check how many days/months between them?

[edited by: Darkelve at 10:41 am (utc) on May 10, 2007]

bmcgee

5:43 am on May 12, 2007 (gmt 0)

10+ Year Member



DateAdd(m, -3, now())

Will return you the date three months ago.

wisneski

2:08 am on May 14, 2007 (gmt 0)

10+ Year Member



Would this do the trick?

IF isDate(dtmSaleDate) Then
'There is a date
IF (DateDiff("d",dtmSaleDate,Now()) < 90) THEN
'Sale was less than 90 days ago
'Show the text
END IF
END IF

wisneski

1:07 pm on May 14, 2007 (gmt 0)

10+ Year Member



I should have mentioned...my response uses ASP, not ASP.net. I'm not sure which you were looking for, Darkelve.

Darkelve

7:46 am on May 15, 2007 (gmt 0)

10+ Year Member



Hi everyone.

Yes, I am using ASP. I used the datediff function, this turned out to be all I needed!

Thanks, my problem is solved now.