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/Code)
 Displaying Time
 New Topic  Topic Locked
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 2

RebelTech
Average Member

USA
613 Posts

Posted - 11 October 2003 :  14:44:37  Show Profile  Visit RebelTech's Homepage  Send RebelTech an ICQ Message
I suspect I can do this and I am guessing it is simple since Snitz already does time functions. Can anyone tell what the code would be to simply put the time (at page load I gues) in the footer. I can see where it would go in the inc_footer.asp. Also, how would I get it to reflect UTC time(-6hours here).
Thanks

Edited by - Roland on 12 October 2003 00:44:12

Roland
Advanced Member

Netherlands
9335 Posts

Posted - 11 October 2003 :  15:33:10  Show Profile
Here's what I'd do (don't know if it's the best way to go about this, but it works):

Dim strTimeNow, strHourNow, strMinNow, strSecNow
strHourNow = Hour(Now())
strMinNow = Minute(Now())
strSecNow = Second(Now())
strTimeOffset = X
strTimeNow = (strHourNow - strTimeOffset) & ":" & strMinNow & ":" & strSecNow


If the server's time is three hours ahead of you, you'll want to change the red X to 3
If your time is ahead of the server's time, you'll want to change the green hyphen to a + sign

Then all that's left is to call strTimeNow and it'll work
Go to Top of Page

RebelTech
Average Member

USA
613 Posts

Posted - 11 October 2003 :  16:46:34  Show Profile  Visit RebelTech's Homepage  Send RebelTech an ICQ Message
Thanks! You did it again. Worked like a charm.
Scott
Go to Top of Page

Roland
Advanced Member

Netherlands
9335 Posts

Posted - 11 October 2003 :  17:09:27  Show Profile
You're welcome, glad I could help
Go to Top of Page

RebelTech
Average Member

USA
613 Posts

Posted - 11 October 2003 :  17:29:30  Show Profile  Visit RebelTech's Homepage  Send RebelTech an ICQ Message
Is there an easy method for formatting the output? For example below is what I have showing.
 21:7:15  UTC
Is there a way to make sure each place (hours/minutes/seconds) has two digits?
Go to Top of Page

altisdesign
Junior Member

United Kingdom
357 Posts

Posted - 11 October 2003 :  17:59:32  Show Profile
Add one more line (highlighted in red)

Dim strTimeNow, strHourNow, strMinNow, strSecNow
strHourNow = Hour(Now())
strMinNow = Minute(Now())
strSecNow = Second(Now())
strTimeOffset = X
strTimeNow = (strHourNow - strTimeOffset) & ":" & strMinNow & ":" & strSecNow
strTimeNow = FormatDateTime(strTimeNow)


This will format it with the two digit correct form as you want

Altis Design offers all manner of web design services to a variety of commercial and personal clients
Go to Top of Page

RebelTech
Average Member

USA
613 Posts

Posted - 11 October 2003 :  18:20:15  Show Profile  Visit RebelTech's Homepage  Send RebelTech an ICQ Message
strTimeNow = FormatDateTime(strTimeNow)
Didn't seem to work. See Below: It appears to have removed Military or 24 hour time.

9:56:08 PM  UTC

Should have been:
21:56:08  UTC

Edited by - RebelTech on 11 October 2003 18:20:38
Go to Top of Page

altisdesign
Junior Member

United Kingdom
357 Posts

Posted - 11 October 2003 :  18:27:56  Show Profile
Oh sorry I thought you just wanted 2 digit form.. didn't realise about the 24 hour

Altis Design offers all manner of web design services to a variety of commercial and personal clients
Go to Top of Page

RebelTech
Average Member

USA
613 Posts

Posted - 11 October 2003 :  18:47:20  Show Profile  Visit RebelTech's Homepage  Send RebelTech an ICQ Message
Ok, I took what all of yall gave and googled the internet for vbscript. Does there look like there is anything wrong with this? Will this work?
<%
Dim strTimeNow
If Len(DatePart("n",Now()))=1 Then
n = 0 & DatePart("n",Now())
Else
n = DatePart("n",Now())
End If
If Len(DatePart("s",Now()))=1 Then
s = 0 & DatePart("s",Now())
Else
s = DatePart("s",Now())
End If
strHourNow=Hour(Now)




strTimeOffset = 4
strTimeNow = (strHourNow + strTimeOffset) & ":" & n & ":" & s 
Response.Write "      <table border=""0"" bordercolor=""" & strTableBorderColor & """ align=""left"" cellPadding=""4"" cellSpacing=""0"" width=""100%"">" & vbNewLine & _
		"  <tr>" & vbNewLine & _
		"    <td width=""40%"" valign=""top"" >" & vbNewLine & _
		"<font face=""" & strDefaultFontFace & """ size=""" & strDefaultFontSize & """ color=""" & strHeadFontColor & """><b> " &strTimeNow& "  UTC </b></font>" & vbNewLine & _
        "    </td>" & vbNewLine & _
		"    <td width=""60%"" align=""left"">" & vbNewLine 

%>
Go to Top of Page

RebelTech
Average Member

USA
613 Posts

Posted - 11 October 2003 :  18:48:24  Show Profile  Visit RebelTech's Homepage  Send RebelTech an ICQ Message
disregard all the table stuff
Go to Top of Page

altisdesign
Junior Member

United Kingdom
357 Posts

Posted - 11 October 2003 :  18:51:24  Show Profile
I changed Frutzle's code above for you to this:


Dim strTimeNow, strHourNow, strMinNow, strSecNow
strHourNow = Hour(Now())
strMinNow = Minute(Now())
strSecNow = Second(Now())

If Len(strSecNow)=0 Then
  strSecNow = "00"
ElseIf Len(strSecNow)=1 Then
  strSecNow = "0" & strSecNow
End If

strTimeOffset = X
strTimeNow = (strHourNow - strTimeOffset) & ":" & strMinNow 
strTimeNow = FormatDateTime(strTimeNow, vbShortTime) & ":" & strSecNow


I don't know if there is a function to do it in VB, but if there is, I couldn't find it on MSDN

Altis Design offers all manner of web design services to a variety of commercial and personal clients

Edited by - altisdesign on 11 October 2003 18:52:08
Go to Top of Page

RebelTech
Average Member

USA
613 Posts

Posted - 11 October 2003 :  19:06:34  Show Profile  Visit RebelTech's Homepage  Send RebelTech an ICQ Message
Thank both of you for the quick replies. I do really appreciate it. You know how it is when you decide you want to do something to your forums. I couldn't wait to get this one solved.
altisdesign, looks like we both were posting about the same time.
Is there any difference in the two codes? I have to admit that I think I understand what you two wrote. The code I got from the internet, I know seems to work but, I don't really grasp it. Why does one script check for "=0" and the other for "=1"?
Go to Top of Page

altisdesign
Junior Member

United Kingdom
357 Posts

Posted - 11 October 2003 :  19:17:26  Show Profile
quote:
Originally posted by RebelTech

Thank both of you for the quick replies. I do really appreciate it. You know how it is when you decide you want to do something to your forums. I couldn't wait to get this one solved.
altisdesign, looks like we both were posting about the same time.
Is there any difference in the two codes? I have to admit that I think I understand what you two wrote. The code I got from the internet, I know seems to work but, I don't really grasp it. Why does one script check for "=0" and the other for "=1"?




Its a different way of doing it that other code, using datepart instead of hour() minute() second(). I prefer Frutzle's method personally, its clearer for me to understand as well. If both methods work, then use whichever is best for you. Heres the code you posted commented to hopefully make you grasp it better:


<%
Dim strTimeNow

'gets number of minutes past the hour, works out if it is missing a preceding digit
If Len(DatePart("n",Now()))=1 Then
'adds a preceding 0 if required
n = 0 & DatePart("n",Now())
Else
n = DatePart("n",Now())
End If

'gets number of seconds in the minute, works out if it is missing a preceding digit
If Len(DatePart("s",Now()))=1 Then
'adds a preceding 0 if required
s = 0 & DatePart("s",Now())
Else
s = DatePart("s",Now())
End If

'gets number of hours past midnight, number between 0-23
strHourNow=Hour(Now)

'offsets the time by the required amount and constructs final strTimeNow variable
strTimeOffset = 4
strTimeNow = (strHourNow + strTimeOffset) & ":" & n & ":" & s 


Note that the code Frutzle / I posted would work better in this situation:

Time is 17:00:00

The code from the internet in that case I believe would return 17:0:0. I havnt tested to find out for sure though. Its not very likely to happen, but worth consdiering. Because Frutzle / my code uses FormatDateTime() this would be returned as it should be, 17:00:00.

Frutzle / my code just used the FormatDateTime() function to convert the minutes into a form where there was a preceding 0, and to convert the time to a 24 hour format, instead of doing another If() statement to check the length of the minutes and adding a preceding 0. This is probly a better way of doing it, but im not sure there's a lot of difference..

Reference:
Datepart - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsfctdatepart.asp
Formatdatetime - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsfctformatdatetime.asp

Hope this helps to understand it a bit better

Altis Design offers all manner of web design services to a variety of commercial and personal clients

Edited by - altisdesign on 11 October 2003 19:20:19
Go to Top of Page

RebelTech
Average Member

USA
613 Posts

Posted - 11 October 2003 :  19:37:43  Show Profile  Visit RebelTech's Homepage  Send RebelTech an ICQ Message
Thank You very much! Your explanation really helped!
The Frutzle / Altidesign code has now been implemented. I even got fancy and commented it giving you two credit!
Go to Top of Page

altisdesign
Junior Member

United Kingdom
357 Posts

Posted - 11 October 2003 :  19:41:42  Show Profile
Glad I could help

Altis Design offers all manner of web design services to a variety of commercial and personal clients
Go to Top of Page

RebelTech
Average Member

USA
613 Posts

Posted - 11 October 2003 :  21:05:45  Show Profile  Visit RebelTech's Homepage  Send RebelTech an ICQ Message
I spoke to soon.
I am getting this error now:
Type mismatch: 'FormatDateTime' 

/forum/inc_footer.asp, line 90


line 90 is in red below:

<%

Dim strTimeNow, strHourNow, strMinNow, strSecNow
strHourNow = Hour(Now())
strMinNow = Minute(Now())
strSecNow = formatnumber(Second(Now()),0,0)

If Len(strSecNow)=0 Then
strSecNow = "00"
ElseIf Len(strSecNow)=1 Then
strSecNow = "0" & strSecNow
End If

strTimeOffset = 4
strTimeNow = (strHourNow + strTimeOffset) & ":" & strMinNow
strTimeNow = FormatDateTime(strTimeNow, vbShortTime) & ":" & strSecNow

It was working....Is it time sensitive?

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.19 seconds. Powered By: Snitz Forums 2000 Version 3.4.07