PDA

View Full Version : ASP datediff errors pls help!



boristheblade
October 3rd, 2003, 06:20 PM
Hey guys I need a little help here with some asp code. I am trying to get the difference in days between two dates. As you can see in the output the dates 'created' and 'today' are legit and print out correctly. Whe I use datediff I get 37897 days for the difference, when it should be about 5-8 days or so.

I have tried to remedy this by formating the dates, I've tried not formating, I've tried just about anything I can think of(which isnt much) :). I am new at asp so any insight is appreciated. thank you so much in advance!

// asp code
<%
createdDate=rs("created")
createdDate = FormatDateTime(createdDate, 2)
today = FormatDateTime(today, 2)
numDays=datediff("d", created, today)
response.write(" created " & createdDate)
response.write(" today " & today)
response.write(" Difference " & numDays)
%>

//OUTPUT

created 9/25/03
today 10/3/03
Difference 37897

created 9/26/03
today 10/3/03
Difference 37897

created 9/27/03
today 10/3/03
Difference 37897

created 10/3/03
today 10/3/03
Difference 37897

created 10/3/03
today 10/3/03
Difference 37897

created 10/3/03
today 10/3/03
Difference 37897

abzoid
October 3rd, 2003, 06:30 PM
Try replacing today with date(), and don't format.

boristheblade
October 3rd, 2003, 06:51 PM
Thanks abzoid,
I just tried that, but i got the same result.

createdDate=rs("created")
numDays=datediff("d", created, date())
response.write(" Difference " & numDays &"<br />")


I still get 37897 as the difference.
If I change "d" to "y" I get 104.

thanks.

abzoid
October 3rd, 2003, 09:36 PM
Your variable name is different in your datediff statement, in both code examples. created should be createdDate.

createdDate=rs("created")
numDays=datediff("d", createdDate, date())
response.write(" Difference " & numDays &"<br />")

boristheblade
October 3rd, 2003, 10:34 PM
Thanks abzoid, I'm gonna go jump off the roof now...

I see now why it was giving the same value for all dates!

Thanks again! I'm retarded

abzoid
October 3rd, 2003, 10:36 PM
no charge ;)

BTDT, more than once.