Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 MOD-Group
 MOD Add-On Forum (W/O Code)
 Calculating 'days since' or 'days to go'
 New Topic  Topic Locked
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 2

StephenD
Senior Member

Australia
1044 Posts

Posted - 26 April 2004 :  09:08:16  Show Profile  Send StephenD a Yahoo! Message
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  Show Profile
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"
Go to Top of Page

StephenD
Senior Member

Australia
1044 Posts

Posted - 26 April 2004 :  09:45:34  Show Profile  Send StephenD a Yahoo! Message
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..
Go to Top of Page

StephenD
Senior Member

Australia
1044 Posts

Posted - 26 April 2004 :  11:32:46  Show Profile  Send StephenD a Yahoo! Message
OK I managed to get the Status_Date to display on my page.http://www.stephendoyle.net/hl_equipment2.asp
U:snitz P:snitz

I'm still struggling to convert this field to a 'days since' calculation. Here is a text version of my page so far:http://www.stephendoyle.net/hl_equipment2.txt
Go to Top of Page

laser
Advanced Member

Australia
3859 Posts

Posted - 26 April 2004 :  17:16:04  Show Profile
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 ?
Go to Top of Page

StephenD
Senior Member

Australia
1044 Posts

Posted - 27 April 2004 :  07:02:25  Show Profile  Send StephenD a Yahoo! Message
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

Go to Top of Page

laser
Advanced Member

Australia
3859 Posts

Posted - 27 April 2004 :  10:32:48  Show Profile
hmmmm : http://www.devguru.com/Technologies/vbscript/quickref/formatdatetime.html

Maybe VBLongDate, but I didn't thinknk it would be case-sensitive.
Go to Top of Page

StephenD
Senior Member

Australia
1044 Posts

Posted - 27 May 2004 :  02:32:11  Show Profile  Send StephenD a Yahoo! Message
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?
Go to Top of Page

Nertz
Junior Member

Canada
341 Posts

Posted - 27 May 2004 :  08:36:36  Show Profile
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
Go to Top of Page

laser
Advanced Member

Australia
3859 Posts

Posted - 27 May 2004 :  13:49:42  Show Profile
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 ?
Go to Top of Page

StephenD
Senior Member

Australia
1044 Posts

Posted - 28 May 2004 :  00:05:03  Show Profile  Send StephenD a Yahoo! Message
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?
Go to Top of Page

laser
Advanced Member

Australia
3859 Posts

Posted - 28 May 2004 :  05:08:20  Show Profile
I think you'll need to convert it to Date format first
Go to Top of Page

StephenD
Senior Member

Australia
1044 Posts

Posted - 28 May 2004 :  07:02:25  Show Profile  Send StephenD a Yahoo! Message
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

Go to Top of Page

laser
Advanced Member

Australia
3859 Posts

Posted - 28 May 2004 :  18:05:09  Show Profile
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.
Go to Top of Page

StephenD
Senior Member

Australia
1044 Posts

Posted - 29 May 2004 :  23:13:46  Show Profile  Send StephenD a Yahoo! Message
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
Go to Top of Page

StephenD
Senior Member

Australia
1044 Posts

Posted - 29 May 2004 :  23:38:13  Show Profile  Send StephenD a Yahoo! Message
Actually it works for Status_date = #15/03/2004# too.
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Next Page
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.96 seconds. Powered By: Snitz Forums 2000 Version 3.4.07