Author |
Topic  |
StephenD
Senior Member
   
Australia
1044 Posts |
Posted - 26 April 2004 : 09:08:16
|
I'd like some code that will calculate how many days since a date - say using the T_EVENT_DATE field in the Calendar Mod.
eg if the event was on 19/03/04 then the result should be 7 days.
And the same for days to go before an event.
Anyone got any ideas? |
|
laser
Advanced Member
    
Australia
3859 Posts |
Posted - 26 April 2004 : 09:21:07
|
This might help :
Response.Write (FormatDateTime(rs("Closing_date"), vbLongDate) & " @ " & FormatDateTime(rs("Closing_date"), vbLongTime) & "<br>")
minutesTotal = (rs("closing_date") - (Now()+STRTIMEADJUST/24)) * 24 * 60
hoursTotal = int(minutesTotal / 60)
daysSince = int(hoursTotal / 24)
hoursSince = hoursTotal mod 24
minutesSince = minutestotal mod 60
if daysSince = 1 then Response.Write daysSince & " day, "
if daysSince > 1 then Response.Write daysSince & " days, "
if hoursSince = 1 then Response.Write hoursSince & " hour,"
if hoursSince > 1 then Response.Write hoursSince & " hours, "
Response.Write minutesSince & " minutes to go"
|
 |
|
StephenD
Senior Member
   
Australia
1044 Posts |
Posted - 26 April 2004 : 09:45:34
|
Thanks Laser
How would I incorporate your code into this statement. At the moment my code has a simple: Days_Since = arrTopicData(tT_EVENT_DATE,iTopic)
Using your code:
Response.Write (FormatDateTime(rs("Closing_date"), vbShortDate))
daysTotal = (rs("closing_date") - (Now()+STRTIMEADJUST/24))
daysSince = int(daysTotal / 24)
if daysSince = 1 then Response.Write daysSince & " day, "
if daysSince > 1 then Response.Write daysSince & " days, "
The ideal end result would be:
Response.Write " <td bgcolor=""" & strForumCellColor & """ valign=""middle"" align=""center""> <font face=""" & strDefaultFontFace & """ size=""" & strDefaultFontSize & """ color=""" & strForumFontColor & """>" & Days_Since & "</font></td>" & vbNewline
I hope this makes sense.. |
 |
|
StephenD
Senior Member
   
Australia
1044 Posts |
|
laser
Advanced Member
    
Australia
3859 Posts |
Posted - 26 April 2004 : 17:16:04
|
I'd try this :
replace line 341 with these several lines :
Response.Write (FormatDateTime(Status_Date, vbLongDate) & "<br>")
minutesTotal = (Status_Date - (Now()+STRTIMEADJUST/24)) * 24 * 60
hoursTotal = int(minutesTotal / 60)
daysSince = int(hoursTotal / 24)
hoursSince = hoursTotal mod 24
minutesSince = minutestotal mod 60
if daysSince = 0 then Response.Write " today "
if daysSince = -1 then Response.Write daysSince & " day ago "
if daysSince < -1 then Response.Write daysSince & " days ago "
That should replace your date display with a "days ago" display. Do you want just the since number or do you want the date as well ? |
 |
|
StephenD
Senior Member
   
Australia
1044 Posts |
Posted - 27 April 2004 : 07:02:25
|
Thanks Laser, having both would be good. eg
11 days 15 Apr 2003
I get this error with the first line of your code above:
Microsoft VBScript runtime error '800a0005'
Invalid procedure call or argument: 'FormatDateTime'
/hl_equipment2.asp, line 342
|
 |
|
laser
Advanced Member
    
Australia
3859 Posts |
|
StephenD
Senior Member
   
Australia
1044 Posts |
Posted - 27 May 2004 : 02:32:11
|
I've only been able to revisit this today and it doesn't seem to be case sensitive.. I get the same error. Would love to see this working. Anyone? |
 |
|
Nertz
Junior Member
 
Canada
341 Posts |
Posted - 27 May 2004 : 08:36:36
|
Would the VB DateDiff function work for you?
DateDiff("d",date1,date2)
cheers, Nat |
Sadly, most Family Court Judges wrongfully reward opportunistic gold diggers that use our children unjustly as "instruments" of power.
www.fathers-4-justice-canada.ca |
 |
|
laser
Advanced Member
    
Australia
3859 Posts |
Posted - 27 May 2004 : 13:49:42
|
Stephen, that code is more or less the code I use in my Tipping comp, using a Date field from Access as the input. I'd try breaking down line 342 a little more because it should work fine. Maybe hard-code a few dates and test it that way ? |
 |
|
StephenD
Senior Member
   
Australia
1044 Posts |
Posted - 28 May 2004 : 00:05:03
|
OK I tried hardcoding a date eg. Status_Date = "6/04/04" and I get the following error:
06 April 2004
Microsoft VBScript runtime error '800a000d'
Type mismatch: '[string: "6/04/04"]'
/hl_equipment2.asp, line 345
Which relates to this line:
Response.Write (FormatDateTime(Status_Date, vbLongDate) & "<br>")
minutesTotal = (Status_Date - (Now()+STRTIMEADJUST/24)) * 24 * 60
hoursTotal = int(minutesTotal / 60)
daysSince = int(hoursTotal / 24)
hoursSince = hoursTotal mod 24
minutesSince = minutestotal mod 60
if daysSince = 0 then Response.Write " today "
if daysSince = -1 then Response.Write daysSince & " day ago "
if daysSince < -1 then Response.Write daysSince & " days ago "
Maybe it has something to do with my server date time setting. I have it set to UK Med?
|
 |
|
laser
Advanced Member
    
Australia
3859 Posts |
Posted - 28 May 2004 : 05:08:20
|
I think you'll need to convert it to Date format first  |
 |
|
StephenD
Senior Member
   
Australia
1044 Posts |
Posted - 28 May 2004 : 07:02:25
|
OK so I changed it to: Status_Date = "20040315142943" (is this right?)
Get the original error again:
Microsoft VBScript runtime error '800a0005'
Invalid procedure call or argument: 'FormatDateTime'
/hl_equipment2.asp, line 344
|
 |
|
laser
Advanced Member
    
Australia
3859 Posts |
Posted - 28 May 2004 : 18:05:09
|
Actually that is the Snitz way that stores it as a number (from memory).
You could try
Status_date = Date() or Status_date = #03/15/2004#
That should work, I usually just use dates pulled from the database. |
 |
|
StephenD
Senior Member
   
Australia
1044 Posts |
Posted - 29 May 2004 : 23:13:46
|
Alright Laser, the second hardcoding option worked thankyou. This is the result: www.stephendoyle.net/hl_equipment3.asp This is the code that I've used:Response.Write " <td bgcolor=""" & strForumCellColor & """ valign=""middle"" align=""center""> <font face=""" & strDefaultFontFace & """ size=""" & strDefaultFontSize & """ color=""" & strForumFontColor & """>" & FormatDateTime(Status_Date, vbLongDate) & "<br />" & vbNewline
minutesTotal = (Status_Date - (Now()+STRTIMEADJUST/24)) * 24 * 60
hoursTotal = int(minutesTotal / 60)
daysSince = int(hoursTotal / 24)
hoursSince = hoursTotal mod 24
minutesSince = minutestotal mod 60
if daysSince = 0 then Response.Write "<font face=""" & strDefaultFontFace & """ size=""" & strFooterFontSize & """ color=""" & strForumFontColor & """>" & " today " & "</font></td>"
if daysSince = -1 then Response.Write daysSince & "<font face=""" & strDefaultFontFace & """ size=""" & strFooterFontSize & """ color=""" & strForumFontColor & """>" & " day ago " & "</font></td>"
if daysSince < -1 then Response.Write daysSince & "<font face=""" & strDefaultFontFace & """ size=""" & strFooterFontSize & """ color=""" & strForumFontColor & """>" & " days ago " & "</font></td>"
Why won't it convert the dates stored in the DB? Does the date need to be converted before processing into this script? For example, when I input the date in post.asp it is in the UK/AUS format 15/3/2004. |
Edited by - StephenD on 29 May 2004 23:17:15 |
 |
|
StephenD
Senior Member
   
Australia
1044 Posts |
Posted - 29 May 2004 : 23:38:13
|
Actually it works for Status_date = #15/03/2004# too. |
 |
|
Topic  |
|