Click to See Complete Forum and Search --> : Server in another country. I need to add 2 hours system wide


karen987
03-16-2008, 04:16 AM
I have a news weblog with asp pages. I need to make a system wide change so that the articles are showing 2 hours ahead in the public view. This is because the server is in another country. I'd need to be able to adjust for daylight saving.

I think the common file for this is the include file "config.asp", and i have included the code below.

Here is a page example which shows the political news in posted date order, latest on top. Call it "page.asp"


<%Dim iStart, iOffset, SQL, RS, EOF_VAL, strRETURNED_DATA, iRows, iCols, iStop, iRowLoop, strPREV_LINK, strNEXT_LINK, CID, CNAME, AUTHOR, NID, SUMMARY, IMAGE, CATEGORIES, TITLE, POSTED, XI

CID = Trim(Request.QueryString("CID"))
CNAME = Request("CNAME")
iStart = Request.QueryString("Start")
iOffset = Request.QueryString("Offset")


IF IS_VALID_ID(CID) THEN

If Not IsNumeric(iStart) or Len(iStart) = 0 then
iStart = 0
Else
iStart = CInt(iStart)
End If
If Not IsNumeric(iOffset) or Len(iOffset) = 0 then
iOffset = ALL_ARTICLES_PAGE_SIZE
Else
iOffset = Cint(iOffset)
End If

IF DB_TO_USE = 1 OR DB_TO_USE = 3 THEN
SQL = "SELECT nm_tbl_news.ID AS NID, nm_tbl_news.fldSUMMARY AS SUMMARY, nm_tbl_news.fldIMAGE AS NIMAGE, nm_tbl_news.fldTITLE AS TITLE, nm_tbl_agent.fldNAME AS ANAME, nm_tbl_news.fldPOSTED AS POSTED FROM nm_tbl_news, nm_tbl_agent WHERE (nm_tbl_agent.ID = nm_tbl_news.fldAID) AND (nm_tbl_news.fldACTIVE=1) AND (Now() BETWEEN fldPOSTED AND fldEXPIRES) AND (nm_tbl_news.ID IN (SELECT fldNEWS_ID FROM nm_tbl_news_cate WHERE fldCATE_ID = " & CID & ")) ORDER BY nm_tbl_news.ID DESC"
ELSE
SQL = "SELECT nm_tbl_news.ID AS NID, nm_tbl_news.fldSUMMARY AS SUMMARY, nm_tbl_news.fldIMAGE AS NIMAGE, nm_tbl_news.fldTITLE AS TITLE, nm_tbl_agent.fldNAME AS ANAME, nm_tbl_news.fldPOSTED AS POSTED FROM nm_tbl_news, nm_tbl_agent WHERE (nm_tbl_agent.ID = nm_tbl_news.fldAID) AND (nm_tbl_news.fldACTIVE=1) AND (GetDate() BETWEEN fldPOSTED AND fldEXPIRES) AND (nm_tbl_news.ID IN (SELECT fldNEWS_ID FROM nm_tbl_news_cate WHERE fldCATE_ID = " & CID & ")) ORDER BY nm_tbl_news.ID DESC"
END IF

Call OPEN_DB()

Set RS = MyConn.Execute(SQL)
IF NOT RS.EOF THEN
strRETURNED_DATA = RS.getrows
EOF_VAL = False
ELSE
EOF_VAL = True
END IF
RS.close
Set RS = Nothing
' Get settings
Dim DATE_F
DATE_F = GET_SETTINGS(False, "fldDATE_F")


IF not EOF_VAL = True THEN
iRows = UBound(strRETURNED_DATA, 2)
iCols = UBound(strRETURNED_DATA, 1)
If iRows > (iOffset + iStart) Then
iStop = iOffset + iStart - 1
Else
iStop = iRows
End If
FOR iRowLoop = iStart to iStop
NID = strRETURNED_DATA(0, iRowLoop)
SUMMARY = strRETURNED_DATA(1, iRowLoop)
IMAGE = strRETURNED_DATA(2, iRowLoop)
TITLE = strRETURNED_DATA(3, iRowLoop)
AUTHOR = strRETURNED_DATA(4, iRowLoop)
POSTED = strRETURNED_DATA(5, iRowLoop)
TITLE = PROCESS_SHORTCUTS(False, TITLE)
SUMMARY = PROCESS_SHORTCUTS(False, SUMMARY)
CATEGORIES = GET_CATES(NID)
%>


<table cellpadding="2" cellspacing="0" border="0" width="100%"><tr>
<td><div align="justify"><a href="page.asp?ID=<%=NID%>" class="aTITLE"><%= TITLE %></a></div></td>
</tr>
<tr><td colspan="2" class="divPOSTEDON"><div align="justify"><%= FormatDateTime(POSTED,DATE_F) %>
<% IF SHOW_AUTHOR = True THEN %>
By:<%= AUTHOR %>
<% Else %>

<% End If %>
</div></td></tr>
<tr><td colspan="2" class="tdSUMMARY"><div align="justify">
<%IF NOT (IMAGE = "" OR IsNull(IMAGE)) THEN%>
<img src="<%=IMAGE%>" width="50" height="50" border="1" align="left" />
<% END IF %>
<%= SUMMARY %></div></td></tr>
</table>
<div align="justify"><hr width="100%" size="1" style="color: gray;height: 1px;width: 100%;" />

<%
NEXT
' Close DB
MyConn.close
Set MyConn = Nothing

If iStart > 0 Then
strPREV_LINK = "<A class=""clsPAGING"" HREF=""politics.asp?Start=" & iStart-iOffset & "&Offset=" & iOffset & "&CID=" & CID & """>Previous " & iOffset & "</A>"
Else
strPREV_LINK = " "
End If
If iStop < iRows Then
strNEXT_LINK = " <A class=""clsPAGING"" HREF=""politics.asp?Start=" & iStart+iOffset & "&Offset=" & iOffset & "&CID=" & CID & """>Next " & iOffset & "</A>"
Else
strNEXT_LINK = " "
End If %>

<table width="100%" align="center" cellpadding="2" cellspacing="0" border="0"><tr class="trPAGING">
<td width="50%" align="left"><%=strPREV_LINK%></td>
<td width="50%" align="right"><%=strNEXT_LINK%></td>
</tr></table>

<%ELSE%>

<table width="100%" align="center" cellpadding="2" cellspacing="0" border="0"><tr><td>No political news yet</td></tr></table>

<%END IF%>
<%END IF%>



and i believe this is the common code which is used for all the dates, and it's in the include file which is included in the header file and it's called "config.asp". I have only shown the code which i think is relevant to the dating of articles below:

Is there something i can add below to make a system wide change of 2 hours ahead? I'd need to be able to adjust for daylight, so i presume it's a matter of changing only the number for the hours somewhere.


config.asp


' Assemble date value
FUNCTION ASEMBLE_DATE_FORMAT(sDAY, sMONTH, sYEAR)
Dim DATE_FORMAT, sDATE

DATE_FORMAT = 1 ' US Locale

SELECT CASE DATE_FORMAT
CASE 1
sDATE = sMONTH & "/" & sDAY & "/" & sYEAR
CASE ELSE
sDATE = sMONTH & "/" & sDAY & "/" & sYEAR
END SELECT
ASEMBLE_DATE_FORMAT = sDATE
END FUNCTION



END SUB
%>

and this

It does actually say, that there is no need to modify it, but that may be because the other things on the config.asp page are customisable, ie. email, and number of articles etc.

config.asp


<% '// NO NEED TO MODIFY ANYTHING BELOW
FUNCTION CNT_DATE(sDATE)
IF IsDate(sDATE) = True THEN
SELECT CASE DATE_FORMAT
CASE 1 'YYYYMMDD
CNT_DATE = Year(sDATE) & Right(Cstr(Month(sDATE) + 100),2) & Right(Cstr(Day(sDATE) + 100),2)
CASE 2 'YYYY-MM-DD
CNT_DATE = Year(sDATE) & "-" & Right(Cstr(Month(sDATE) + 100),2) & "-" & Right(Cstr(Day(sDATE) + 100),2)
CASE 101 'mm/dd/yy
CNT_DATE = Right(Cstr(Month(sDATE) + 100),2) & "/" & Right(Cstr(Day(sDATE) + 100),2) & "/" & Right(Cstr(Year(sDATE)),2)
CASE 102 'yy.mm.dd
CNT_DATE = Right(Cstr(Year(sDATE)),2) & "." & Right(Cstr(Month(sDATE) + 100),2) & "." & Right(Cstr(Day(sDATE) + 100),2)
CASE 103 'dd/mm/yy
CNT_DATE = Right(Cstr(Day(sDATE) + 100),2) & "/" & Right(Cstr(Month(sDATE) + 100),2) & "/" & Right(Cstr(Year(sDATE)),2)
CASE 104 'dd.mm.yy
CNT_DATE = Right(Cstr(Day(sDATE) + 100),2) & "." & Right(Cstr(Month(sDATE) + 100),2) & "." & Right(Cstr(Year(sDATE)),2)
CASE 105 'dd-mm-yy
CNT_DATE = Right(Cstr(Day(sDATE) + 100),2) & "-" & Right(Cstr(Month(sDATE) + 100),2) & "-" & Right(Cstr(Year(sDATE)),2)
CASE 110 'mm-dd-yy
CNT_DATE = Right(Cstr(Month(sDATE) + 100),2) & "-" & Right(Cstr(Day(sDATE) + 100),2) & "-" & Right(Cstr(Year(sDATE)),2)
CASE 111 'yy/mm/dd
CNT_DATE = Right(Cstr(Year(sDATE)),2) & "/" & Right(Cstr(Month(sDATE) + 100),2) & "/" & Right(Cstr(Day(sDATE) + 100),2)
CASE 112 'yymmdd
CNT_DATE = Right(Cstr(Year(sDATE)),2) & Right(Cstr(Month(sDATE) + 100),2) & Right(Cstr(Day(sDATE) + 100),2)
END SELECT
ELSE
CNT_DATE = Null
END IF
END FUNCTION
%>


Much appreciated, if anyone could give me some advice.

yamaharuss
03-16-2008, 08:24 AM
If you're just wanting to add 2 hours to any date....

MyNewdate=dateAdd ("h",2,MyDate)

karen987
03-16-2008, 08:56 AM
If you're just wanting to add 2 hours to any date....

MyNewdate=dateAdd ("h",2,MyDate)

Thank you for replying Yamaharuss,

Sorry, i'm not html literate. Where do i add this code? to the config.asp file? That is the common file for all the pages. i'm hoping i'll only have to change the code once somewhere, rather than on the many pages i have.

thanks in advance.

yamaharuss
03-16-2008, 07:53 PM
Add it to your function:

FUNCTION CNT_DATE(sDATE)
sDATE=dateAdd ("h",2,sDATE)
blah.....

karen987
03-18-2008, 02:55 PM
actually sorry the code on the page doesn't use the config.asp file, i'll have to alter the code on these 2 pages. Here is the code




<% ' Dim SQL_SIDE, RS_SIDE, NID, TITLE, POSTED, NEWS_LISTING, SHOW_HL, MyConn_SIDE, I_SIDE, SUMMARY, CATE_ID, ANAME




' ------------------------------------------------------------------------------------------------------------------

' DATABASE CONNECTION

Set MyConn_SIDE = Server.CreateObject("ADODB.Connection")
MyConn_SIDE.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=e:\domains).mdb;"


' NUMBER OF HEADLINES TO SHOW

SHOW_HL = 18

' Set to 1 if you are using MS Access, set to 2 if you are using MS SQL database

DB_TO_USE_CUSTOM = 1

' Category ID to pull the articles from

CATE_ID = "108"

' ------------------------------------------------------------------------------------------------------------------







SELECT CASE DB_TO_USE_CUSTOM
CASE 1
SQL_SIDE = "SELECT TOP " & SHOW_HL & " nm_tbl_news.ID AS NID, nm_tbl_news.fldTITLE AS TITLE, nm_tbl_agent.fldNAME AS ANAME, nm_tbl_news.fldPOSTED AS POSTED, fldSUMMARY, nm_tbl_news.fldIMAGE AS NIMAGE FROM nm_tbl_news, nm_tbl_agent WHERE (nm_tbl_agent.ID = nm_tbl_news.fldAID) AND (nm_tbl_news.fldACTIVE=1) AND (Now() BETWEEN fldPOSTED AND fldEXPIRES) AND nm_tbl_news.ID IN (SELECT fldNEWS_ID FROM nm_tbl_news_cate WHERE fldCATE_ID = " & CATE_ID & ") ORDER BY nm_tbl_news.ID DESC"
CASE 2
SQL_SIDE = "SELECT TOP " & SHOW_HL & " nm_tbl_news.ID AS NID, nm_tbl_news.fldTITLE AS TITLE, nm_tbl_news.fldPOSTED AS POSTED, fldSUMMARY, nm_tbl_news.fldIMAGE AS NIMAGE FROM nm_tbl_news, nm_tbl_agent WHERE (nm_tbl_agent.ID = nm_tbl_news.fldAID) AND (nm_tbl_news.fldACTIVE=1) AND (GetDate() BETWEEN fldPOSTED AND fldEXPIRES) AND nm_tbl_news.ID IN (SELECT fldNEWS_ID FROM nm_tbl_news_cate WHERE fldCATE_ID = " & CATE_ID & ") ORDER BY nm_tbl_news.ID DESC"
CASE 3
SQL_SIDE = "SELECT nm_tbl_news.ID AS NID, nm_tbl_news.fldTITLE AS TITLE, nm_tbl_news.fldPOSTED AS POSTED, fldSUMMARY, nm_tbl_news.fldIMAGE AS NIMAGE FROM nm_tbl_news, nm_tbl_agent WHERE (nm_tbl_agent.ID = nm_tbl_news.fldAID) AND (nm_tbl_news.fldACTIVE=1) AND (Now() BETWEEN fldPOSTED AND fldEXPIRES) AND nm_tbl_news.ID IN (SELECT fldNEWS_ID FROM nm_tbl_news_cate WHERE fldCATE_ID = " & CATE_ID & ") ORDER BY nm_tbl_news.ID DESC LIMIT " & SHOW_HL
END SELECT


I_SIDE = 0
Set RS_SIDE = Server.CreateObject("ADODB.Recordset")
RS_SIDE.LockType = 1
RS_SIDE.CursorType = 0
RS_SIDE.Open SQL_SIDE, MyConn_SIDE
WHILE NOT RS_SIDE.EOF
NID = trim(RS_SIDE("NID"))
TITLE = trim(RS_SIDE("TITLE"))
POSTED = trim(RS_SIDE("POSTED"))
SUMMARY = trim(RS_SIDE("fldSUMMARY"))
AUTHOR = trim(RS_SIDE("ANAME"))
IMAGE = trim(RS_SIDE("NIMAGE")) & ""
TITLE = PROCESS_SHORTCUTS_INC(False, TITLE)
SUMMARY = PROCESS_SHORTCUTS_INC(False, SUMMARY)
I_SIDE = I_SIDE + 1
IF I_SIDE =< SHOW_HL THEN
%>
<link href="styles.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style2 {color: #808080; font-style: italic;}
-->
</style>




<!--
.style12 {font-size: 12}
-->
</style>
<div align="justify"><a class="aTITLE_ORANGEBLUE" href="../public.asp?ID=<%=NID%>"><%=TITLE%></a><br />
<%IF NOT (IMAGE = "" OR IsNull(IMAGE)) THEN%><img src="<%=IMAGE%>" width="50" height="60" align="left" />
<%END IF%>
<span class="style2"><%= FormatDateTime(POSTED,DATE_F) %></span> <span class="articleBody"><%= SUMMARY %> </span>
<%IF NOT I_SIDE = SHOW_HL THEN%></div>
<hr align="JUSTIFY">
<div align="justify">
<%End If%>


<%
END IF
RS_SIDE.MoveNext
WEND
RS_SIDE.Close
Set RS_SIDE = Nothing
MyConn_SIDE.Close
Set MyConn_SIDE = Nothing

FUNCTION PROCESS_SHORTCUTS_INC(blOPEN, TEXT)
Dim SQL, RS, strRETURNED_DATA, EOF_VAL, intNUM_COL, intNUM_ROW, intROW_COUNTER, strSIGN, strIMAGE
SQL = "SELECT fldSIGN, fldIMAGE FROM nm_tbl_library WHERE fldACTIVE = 1"
Set RS = Server.CreateObject("ADODB.Recordset")
RS.LockType = 1
RS.CursorType = 0
RS.Open SQL, MyConn_SIDE
IF NOT RS.EOF THEN
strRETURNED_DATA = RS.getrows
ELSE
EOF_VAL = True
END IF
RS.close
Set RS = Nothing
IF Not EOF_VAL = True Then
intNUM_COL=ubound(strRETURNED_DATA,1)
intNUM_ROW=ubound(strRETURNED_DATA,2)
FOR intROW_COUNTER = 0 TO intNUM_ROW
strSIGN = Trim(strRETURNED_DATA(0,intROW_COUNTER))
strIMAGE = Trim(strRETURNED_DATA(1,intROW_COUNTER))
strIMAGE = "<img src='" & strIMAGE & "' border='0' alt='' />"
TEXT = Replace(TEXT, strSIGN, strIMAGE)
NEXT
END IF
PROCESS_SHORTCUTS_INC = TEXT
END FUNCTION
%>

and this is "Today's added news" another page which shows all the articles added within the 24 hour period. This page automatically pulls out from midnight to midnight. At the moment it is pulling out news from UK time midnight to midnight. It also has a drop down menu with preivious days newslog for each day.

At midnight each night the page is blank, until news is added. Midnight UK time. However i want it to update 2 hours earlier, because the country that the website represents is 2 hours ahead. So at 10pm UK time, the today's weblog page should be blank, for it would be midnight, and ready for the new days material to be added.

I need to push the time 2 hours. Even though the time doesn't show on the articles, i want the "todays added news" page to update at midngiht (GMT +2) and the articles to show the proper time (2 hours ahead from server time) when showing in public.

I will post the code in a new post as it's too long for this, it follows this post

karen987
03-18-2008, 02:57 PM
Here is the code for the "todays added news" page.


<% Dim SetDate, EndDate, QueryDate, CATEGORIES, POP_DROP

QueryDate = Request.QueryString("D")

If IsDate(QueryDate) THEN
QueryDate = CDate(QueryDate)
ELSe
QueryDate = Date()
END IF

SetDate = QueryDate
EndDate = QueryDate + 1


Call OPEN_DB()

SQL = "SELECT fldCREATED FROM nm_tbl_news GROUP BY fldCREATED ORDER BY fldCREATED DESC"
Set RS = Server.CreateObject("ADODB.Recordset")
RS.LockType = 1
RS.CursorType = 0
RS.Open SQL, MyConn

WHILE NOT RS.EOF
blSEL = ""
If NOT Instr(POP_DROP, FormatDateTime(RS("fldCREATED"),2)) > 0 THEN
'IF Trim(QueryDate) = Trim(FormatDateTime(RS("fldCREATED"),2)) THEN blSEL = " selected"
POP_DROP = POP_DROP & "<option " & blSEL & " value='TodaysWeblog.asp?D=" & FormatDateTime(RS("fldCREATED"),2) & "'>" & FormatDateTime(RS("fldCREATED"),2) & vbcrlf
END IF
RS.MoveNext
WEND
RS.Close
Set RS = Nothing
Dim DATE_F
DATE_F = GET_SETTINGS(False, "fldDATE_F")

%>


<script language="JavaScript" type="text/javascript">
function Jump(fe){
var opt_key = fe.selectedIndex;
var uri_val = fe.options[opt_key].value;
window.open(uri_val,'_top');
return true;
}
</script>


<table width="752" align="center" cellpadding="2" cellspacing="0" border="0">
<tr>
<td> <span style="font-size: 9px; font-style: italic">24 hour weblog for :<strong style="font-size: 12px;"> <%=QueryDate%></strong></span></th>

<tr> <td width="628" align="left" valign="top"><table width="592">
<tr>
<th width="237" align="left" scope="col"><img src="../images1/navig/todaysJPG" alt="todays weblog" width="150" height="21" align="top"></th>
</tr>
</table>

<span class="tdSUMMARY"> <table width="595" height="199" align="left" cellpadding="2" cellspacing="2">
<% Dim I

I = 1
SQL = "SELECT nm_tbl_news.ID AS NID, nm_tbl_news.fldSUMMARY AS SUMMARY, nm_tbl_news.fldIMAGE AS NIMAGE, nm_tbl_news.fldTITLE AS TITLE, nm_tbl_agent.fldNAME AS ANAME, nm_tbl_news.fldPOSTED AS POSTED, fldCREATED FROM nm_tbl_news, nm_tbl_agent WHERE (nm_tbl_agent.ID = nm_tbl_news.fldAID) AND (nm_tbl_news.fldACTIVE=1) AND (fldCREATED > #" & SetDate & "# AND fldPOSTED < #" & EndDate & "# ) AND (Now() BETWEEN fldCREATED AND fldEXPIRES) ORDER BY nm_tbl_news.ID DESC"

Set RS = Server.CreateObject("ADODB.Recordset")
RS.LockType = 1
RS.CursorType = 0
RS.Open SQL, MyConn
If RS.EOF Then
Response.Write "



We regret to inform you that no new content has been added as yet.

.

."
End If
WHILE NOT RS.EOF
NID = trim(RS("NID"))
SUMMARY = trim(RS("SUMMARY"))
IMAGE = trim(RS("NIMAGE"))
TITLE = trim(RS("TITLE"))
AUTHOR = trim(RS("ANAME"))
POSTED = trim(RS("POSTED"))
CREATED = trim(RS("fldCREATED"))
CATEGORIES = GET_CATES(NID)
%></span>
<%'IF Trim(FormatDateTime(POSTED,2)) = Trim(SetDate) THEN%>
<%IF I = 1 THEN%>
<tr>
<td width="585" height="98" align="left" valign="top" style="padding: 5px;"><a href="../view.asp?ID=<%=NID%>" class="NavigLNK"><%=TITLE%></a><br />

<span class="divPOSTEDON">Category: <%=CATEGORIES%></span><%END IF%> <br />

<%IF NOT (IMAGE = "" OR IsNull(IMAGE)) THEN%>
<img src="<%=IMAGE%>" width="70" height="80" vspace="5" border="0" align="left" />
<% END IF %> <%= FormatDateTime(POSTED,DATE_F) %> <%IF SHOW_AUTHOR = True THEN%>
[By: <%=AUTHOR%>]<br />
<span class="tdSUMMARY"><%= SUMMARY %> <br />
</span><br /><hr width="100%" size="1" style="color: gray ;height: 1px;" /> </td>
</tr>
<%ELSE%>
<tr>
<td width="585" align="left" valign="top" style="padding: 5px;; font-size: 12px"><div align="justify">
<%IF NOT (IMAGE = "" OR IsNull(IMAGE)) THEN%>
<img src="<%=IMAGE%>" width="50" height="50" border="1" />
<%ELSE%>

<%END IF%>
</div></td>
</tr>
<%END IF%>
<%'END IF%>
<%
I = I + 1
IF I > 1 THEN I = 1
RS.MoveNext
WEND
RS.Close
Set RS = Nothing

MyConn.Close
Set MyConn = Nothing


%>
</td> </tr></table>
<p> </p>
<p> </p>
<p> </p>
<p> </p>

<td width="150" valign="top">



<p><img src="../images1/navig/.JPG" alt="previousdays" width="150" height="21" vspace="4">
<select class="textbox" name="D" onChange="return Jump(this);" >
<option value=''>Select One ...<%=POP_DROP%>
</select>
</td>



<!--#include file="inc_footer.asp"-->
</table>