I have needed a very simple solution to adding hours to the <%=now()%> function.
This is very simple, it doesn’t take daylight savings into account.
<%
sDate = Now()
sNewDate = DateAdd(“h”, 7, sDate)
%>
<input type=”hidden” name=”date_added” value=”<%=sNewDate%>” />
If your server is hosted in an area that is a couple of hours from you. Firstly find out your local time on that server:
<%=now()%>
Then calculate how many hours difference there is.
If your server time is 7 hours behind you then use this.
<%
sDate = Now()
sNewDate = DateAdd(“h”, 7, sDate)
%>
<input type=”hidden” name=”date_added” value=”<%=sNewDate%>” />
If your server is 7 hours ahead of you then use this.
<%
sDate = Now()
sNewDate = DateAdd(“h”, -7, sDate)
%>
<input type=”hidden” name=”date_added” value=”<%=sNewDate%>” />
You might also want to add or subtract days, months, years, seconds, minutes. Just use these:
s – Second
n – Minute
h – Hour
d – Day
y – Day of year
w – Weekday
ww – Week of year
m – Month
q – Quarter
yyyy – Year
And on this line:
sNewDate = DateAdd(“h”, 7, sDate)
Replace with what you want. If I want the date to have 300 seconds added to it, all you do is this:
sNewDate = DateAdd(“s”, 300, sDate)
I hope that helps.
