Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Time formatting
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Time formatting

 Post Reply Post Reply
Author
PuNkY View Drop Down
Newbie
Newbie


Joined: 13 May 2003
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote PuNkY Quote  Post ReplyReply Direct Link To This Post Topic: Time formatting
    Posted: 12 August 2006 at 7:46am

Hello everyone,
I need a little help. I’m trying to make a script that requires me to show the user how many years/months/weeks/hours/minutes the posted something (like Posted: 2 days 1 hour 3 minutes ago). I have made an attempt but failed. When the post becomes a month old it says something like "32 days" instead of 1 month and also when the post becomes a year old it says "1 year 365 days". Maybe one of you can help me with my script.


<%
Function Time(post_time)
Dim strNow
Dim H
Dim M
Dim Y
Dim D

strNow = Now()

H = datediff("h",post_time,strNow)
M = datediff("n",post_time,strNow)
Y = datediff("yyyy",post_time,strNow)

D = int(h / 24) :if d > 0 then d = d & " days " :do while h >= 24 :h = h - 24 :loop :else d = ""

Do While M >= 60
    M = M - 60
Loop
Do While S >= 60
    S = S - 60
Loop


If H > 0 Then
    H = H & " hours "
Else
    H = ""
End If

If M > 0 Then
    M = M & "minutes "
Else
    M = ""
End If

If Y > 0 Then
    Y = Y & " years "
Else
    Y = ""
End If

Response.Write y & d & h & m & s
End Function
%>

Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 13 August 2006 at 3:07pm
You need to substact the number of years * 12 from the month which in the first year will be 0 (0*12=0),same for the month, you need to substract the days
Back to Top
PuNkY View Drop Down
Newbie
Newbie


Joined: 13 May 2003
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote PuNkY Quote  Post ReplyReply Direct Link To This Post Posted: 14 August 2006 at 5:11am
Originally posted by michael michael wrote:

You need to substact the number of years * 12 from the month which in the first year will be 0 (0*12=0),same for the month, you need to substract the days
Can you give me an example. I dont FULLY understand.
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 14 August 2006 at 6:46pm

Sub sTime(post_time)

Dim y,m,d,h

y= Datepart("yyyy",now()) - Datepart("yyyy",post_time)
m= Datepart("m",now()) - Datepart("m",post_time)
d = Datepart("d",now()) - Datepart("d",post_time)
h = Datepart("h",now()) - Datepart("h",post_time)

If m < 0 THEN m=m+daysInMonth   'there are plenty daysInMonth funcitons on the web
If d < 0 ...... 'same thing here

Response.Write (y & " years " & m & " Month " & d & " days " & h & " hours since ")


End Sub
%>
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.